Line number performance fix

This commit is contained in:
Allen Webster 2020-05-01 06:31:44 -07:00
parent 2051b73cb2
commit 2d1d69e2c9
4 changed files with 68 additions and 20 deletions

View File

@ -378,33 +378,73 @@ draw_query_bar(Application_Links *app, Query_Bar *query_bar, Face_ID face_id, Re
function void function void
draw_line_number_margin(Application_Links *app, View_ID view_id, Buffer_ID buffer, Face_ID face_id, Text_Layout_ID text_layout_id, Rect_f32 margin){ draw_line_number_margin(Application_Links *app, View_ID view_id, Buffer_ID buffer, Face_ID face_id, Text_Layout_ID text_layout_id, Rect_f32 margin){
ProfileScope(app, "draw line number margin");
Scratch_Block scratch(app);
FColor line_color = fcolor_id(defcolor_line_numbers_text);
Rect_f32 prev_clip = draw_set_clip(app, margin); Rect_f32 prev_clip = draw_set_clip(app, margin);
draw_rectangle_fcolor(app, margin, 0.f, fcolor_id(defcolor_line_numbers_back)); draw_rectangle_fcolor(app, margin, 0.f, fcolor_id(defcolor_line_numbers_back));
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id); Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
FColor line_color = fcolor_id(defcolor_line_numbers_text);
i64 line_count = buffer_get_line_count(app, buffer); i64 line_count = buffer_get_line_count(app, buffer);
i64 line_count_digit_count = digit_count_from_integer(line_count, 10); i64 line_count_digit_count = digit_count_from_integer(line_count, 10);
Scratch_Block scratch(app); Fancy_String fstring = {};
u8 *digit_buffer = push_array(scratch, u8, line_count_digit_count);
String_Const_u8 digit_string = SCu8(digit_buffer, line_count_digit_count);
for (i32 i = 0; i < line_count_digit_count; i += 1){
digit_buffer[i] = ' ';
}
Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(visible_range.first)); Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(visible_range.first));
i64 line_number = cursor.line; i64 line_number = cursor.line;
for (;cursor.pos <= visible_range.one_past_last;){
if (line_number > line_count){ Buffer_Cursor cursor_opl = view_compute_cursor(app, view_id, seek_pos(visible_range.one_past_last));
break; i64 one_past_last_line_number = cursor_opl.line + 1;
u8 *small_digit = digit_buffer + line_count_digit_count - 1;
{
u8 *ptr = small_digit;
if (line_number == 0){
*ptr = '0';
} }
else{
for (u64 X = line_number; X > 0; X /= 10){
*ptr = '0' + (X%10);
ptr -= 1;
}
}
}
for (;line_number < one_past_last_line_number &&
line_number < line_count;){
Range_f32 line_y = text_layout_line_on_screen(app, text_layout_id, line_number); Range_f32 line_y = text_layout_line_on_screen(app, text_layout_id, line_number);
Vec2_f32 p = V2f32(margin.x0, line_y.min); Vec2_f32 p = V2f32(margin.x0, line_y.min);
Temp_Memory_Block temp(scratch);
Fancy_String *string = push_fancy_stringf(scratch, 0, line_color, fill_fancy_string(&fstring, 0, line_color, 0, 0, digit_string);
"%*lld", draw_fancy_string(app, face_id, fcolor_zero(), &fstring, p);
line_count_digit_count,
line_number);
draw_fancy_string(app, face_id, fcolor_zero(), string, p);
line_number += 1; line_number += 1;
{
u8 *ptr = small_digit;
for (;;){
if (ptr < digit_buffer){
break;
}
if (*ptr == ' '){
*ptr = '0';
}
if (*ptr == '9'){
*ptr = '0';
ptr -= 1;
}
else{
*ptr += 1;
break;
}
}
}
} }
draw_set_clip(app, prev_clip); draw_set_clip(app, prev_clip);

View File

@ -106,15 +106,22 @@ push_fancy_line(Fancy_Block *block, Fancy_Line *line){
//////////////////////////////// ////////////////////////////////
function Fancy_String*
fill_fancy_string(Fancy_String *ptr, Face_ID face, FColor fore, f32 pre_margin, f32 post_margin,
String_Const_u8 value){
ptr->value = value;
ptr->face = face;
ptr->fore = fore;
ptr->pre_margin = pre_margin;
ptr->post_margin = post_margin;
return(ptr);
}
function Fancy_String* function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore, push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
f32 pre_margin, f32 post_margin, String_Const_u8 value){ f32 pre_margin, f32 post_margin, String_Const_u8 value){
Fancy_String *result = push_array_zero(arena, Fancy_String, 1); Fancy_String *result = push_array_zero(arena, Fancy_String, 1);
result->value = value; fill_fancy_string(result, face, fore, pre_margin, post_margin, value);
result->face = face;
result->fore = fore;
result->pre_margin = pre_margin;
result->post_margin = post_margin;
if (line != 0){ if (line != 0){
push_fancy_string(line, result); push_fancy_string(line, result);
} }

View File

@ -4,6 +4,7 @@
+ New Date_Time system APIs, and Date_Time string formatting + New Date_Time system APIs, and Date_Time string formatting
+ Fix: when generated/metadata* files are missing buildsuper still succeeds + Fix: when generated/metadata* files are missing buildsuper still succeeds
+ Fix: mac does not hang opening multiple files + Fix: mac does not hang opening multiple files
+ Fix: line number margin performance
4.1.4 4.1.4
+ MAJOR: The clipboard history is now a fully custom layer implemented system. Users maintaining a customization layer should try to update their call sites to the old clipboard API. #define FCODER_TRANSITION_TO 4001004 to disable the transitional function wrappers when you are ready to make the transition. + MAJOR: The clipboard history is now a fully custom layer implemented system. Users maintaining a customization layer should try to update their call sites to the old clipboard API. #define FCODER_TRANSITION_TO 4001004 to disable the transitional function wrappers when you are ready to make the transition.