shithub: orca

Download patch

ref: 5e2206f45f74da1aa793a03152dae78748ec6346
parent: ba88a00dadf1416644f284cac877d22a1535c01b
author: cancel <cancel@cancel.fm>
date: Fri Dec 7 12:48:50 EST 2018

Change to use scratch oevent list when predicting ui markers

--- a/bank.c
+++ b/bank.c
@@ -104,6 +104,16 @@
 }
 void oevent_list_deinit(Oevent_list* olist) { free(olist->buffer); }
 void oevent_list_clear(Oevent_list* olist) { olist->count = 0; }
+void oevent_list_copy(Oevent_list const* src, Oevent_list* dest) {
+  Usz src_count = src->count;
+  if (dest->capacity < src_count) {
+    Usz new_cap = orca_round_up_power2(src_count);
+    dest->buffer = realloc(dest->buffer, new_cap * sizeof(Oevent));
+    dest->capacity = new_cap;
+  }
+  memcpy(dest->buffer, src->buffer, src_count * sizeof(Oevent));
+  dest->count = src_count;
+}
 Oevent* oevent_list_alloc_item(Oevent_list* olist) {
   Usz count = olist->count;
   if (olist->capacity == count) {
--- a/bank.h
+++ b/bank.h
@@ -59,5 +59,6 @@
 void oevent_list_init(Oevent_list* olist);
 void oevent_list_deinit(Oevent_list* olist);
 void oevent_list_clear(Oevent_list* olist);
+void oevent_list_copy(Oevent_list const* src, Oevent_list* dest);
 ORCA_FORCE_NO_INLINE
 Oevent* oevent_list_alloc_item(Oevent_list* olist);
--- a/tui_main.c
+++ b/tui_main.c
@@ -588,6 +588,8 @@
 
   Field scratch_field;
   field_init(&scratch_field);
+  Oevent_list scratch_oevent_list;
+  oevent_list_init(&scratch_oevent_list);
 
   Tui_cursor tui_cursor;
   tui_cursor_init(&tui_cursor);
@@ -619,9 +621,8 @@
     if (needs_remarking) {
       field_resize_raw_if_necessary(&scratch_field, field.height, field.width);
       field_copy(&field, &scratch_field);
-      orca_run(field.buffer, markmap_r.buffer, field.height, field.width,
-               tick_num, &bank, &oevent_list, piano_bits);
-      field_copy(&scratch_field, &field);
+      orca_run(scratch_field.buffer, markmap_r.buffer, field.height, field.width,
+               tick_num, &bank, &scratch_oevent_list, piano_bits);
       needs_remarking = false;
     }
     int content_y = 0;
@@ -826,5 +827,6 @@
   field_deinit(&scratch_field);
   undo_history_deinit(&undo_hist);
   oevent_list_deinit(&oevent_list);
+  oevent_list_deinit(&scratch_oevent_list);
   return 0;
 }