Skip to content

Commit

Permalink
Move variables down that are only used when creating LayoutLines and …
Browse files Browse the repository at this point in the history
…replaced used of push_line bool with checking is layout_lines is empty
  • Loading branch information
Imberflur committed Aug 15, 2023
1 parent 046af8c commit e0e9023
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,19 +718,6 @@ impl ShapeLine {
wrap: Wrap,
align: Option<Align>,
) -> Vec<LayoutLine> {
let mut layout_lines = Vec::with_capacity(1);

let align = align.unwrap_or({
if self.rtl {
Align::Right
} else {
Align::Left
}
});

// This is used to create a visual line for empty lines (e.g. lines with only a <CR>)
let mut push_line = true;

// For each visual line a list of (span index, and range of words in that span)
// Note that a BiDi visual line could have multiple spans or parts of them
// let mut vl_range_of_spans = Vec::with_capacity(1);
Expand Down Expand Up @@ -981,6 +968,16 @@ impl ShapeLine {
}

// Create the LayoutLines using the ranges inside visual lines
let mut layout_lines = Vec::with_capacity(1);

let align = align.unwrap_or({
if self.rtl {
Align::Right
} else {
Align::Left
}
});

let start_x = if self.rtl { line_width } else { 0.0 };

let number_of_visual_lines = visual_lines.len();
Expand Down Expand Up @@ -1074,10 +1071,10 @@ impl ShapeLine {
max_descent: max_descent * font_size,
glyphs,
});
push_line = false;
}

if push_line {
// This is used to create a visual line for empty lines (e.g. lines with only a <CR>)
if layout_lines.is_empty() {
layout_lines.push(LayoutLine {
w: 0.0,
max_ascent: 0.0,
Expand Down

0 comments on commit e0e9023

Please sign in to comment.