From 2d1d69e2c9fe77b3d7b8e465e9bec72b9ec1bad2 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 1 May 2020 06:31:44 -0700 Subject: [PATCH] Line number performance fix --- 4ed_api_implementation.cpp | 4 +-- custom/4coder_draw.cpp | 66 ++++++++++++++++++++++++++++++-------- custom/4coder_fancy.cpp | 17 +++++++--- ship_files/changes.txt | 1 + 4 files changed, 68 insertions(+), 20 deletions(-) diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index e81d1a62..0feb4f68 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -1978,8 +1978,8 @@ managed_scope_get_attachment(Application_Links *app, Managed_Scope scope, Manage } else{ #define M \ - "ERROR: scope attachment already exists with a size smaller than the requested size; no attachment pointer can be returned." - print_message(app, string_u8_litexpr(M)); +"ERROR: scope attachment already exists with a size smaller than the requested size; no attachment pointer can be returned." + print_message(app, string_u8_litexpr(M)); #undef M } } diff --git a/custom/4coder_draw.cpp b/custom/4coder_draw.cpp index 139b4dec..d6185d33 100644 --- a/custom/4coder_draw.cpp +++ b/custom/4coder_draw.cpp @@ -378,33 +378,73 @@ draw_query_bar(Application_Links *app, Query_Bar *query_bar, Face_ID face_id, Re 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){ + 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); 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); - - FColor line_color = fcolor_id(defcolor_line_numbers_text); - i64 line_count = buffer_get_line_count(app, buffer); 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)); i64 line_number = cursor.line; - for (;cursor.pos <= visible_range.one_past_last;){ - if (line_number > line_count){ - break; + + Buffer_Cursor cursor_opl = view_compute_cursor(app, view_id, seek_pos(visible_range.one_past_last)); + 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); Vec2_f32 p = V2f32(margin.x0, line_y.min); - Temp_Memory_Block temp(scratch); - Fancy_String *string = push_fancy_stringf(scratch, 0, line_color, - "%*lld", - line_count_digit_count, - line_number); - draw_fancy_string(app, face_id, fcolor_zero(), string, p); + + fill_fancy_string(&fstring, 0, line_color, 0, 0, digit_string); + draw_fancy_string(app, face_id, fcolor_zero(), &fstring, p); + 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); diff --git a/custom/4coder_fancy.cpp b/custom/4coder_fancy.cpp index 4364db02..92017977 100644 --- a/custom/4coder_fancy.cpp +++ b/custom/4coder_fancy.cpp @@ -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* push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore, f32 pre_margin, f32 post_margin, String_Const_u8 value){ Fancy_String *result = push_array_zero(arena, Fancy_String, 1); - result->value = value; - result->face = face; - result->fore = fore; - result->pre_margin = pre_margin; - result->post_margin = post_margin; + fill_fancy_string(result, face, fore, pre_margin, post_margin, value); if (line != 0){ push_fancy_string(line, result); } diff --git a/ship_files/changes.txt b/ship_files/changes.txt index 965c2215..e587f29e 100644 --- a/ship_files/changes.txt +++ b/ship_files/changes.txt @@ -4,6 +4,7 @@ + New Date_Time system APIs, and Date_Time string formatting + Fix: when generated/metadata* files are missing buildsuper still succeeds + Fix: mac does not hang opening multiple files + + Fix: line number margin performance 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.