shithub: orca

Download patch

ref: 7cd10dd0bf0b80569cb186ca2c32480f89dc14d9
parent: 62bad19cae1b990006ab28c3f3348816cd502044
author: cancel <cancel@cancel.fm>
date: Wed Jan 1 19:01:05 EST 2020

Move mbuffer_* functions out of mark.h to gbuffer.h

They are more similar to the stuff in gbuffer.h. If you want what's in
gbuffer.h, you also probably want the mbuffer_* stuff.

--- a/gbuffer.c
+++ b/gbuffer.c
@@ -73,3 +73,8 @@
     p += f_width;
   }
 }
+
+void mbuffer_clear(Mark* mbuf, Usz height, Usz width) {
+  Usz cleared_size = height * width;
+  memset(mbuf, 0, cleared_size);
+}
--- a/gbuffer.h
+++ b/gbuffer.h
@@ -44,3 +44,49 @@
 ORCA_FORCE_NO_INLINE
 void gbuffer_fill_subrect(Glyph* gbuf, Usz grid_h, Usz grid_w, Usz y, Usz x,
                           Usz height, Usz width, Glyph fill_char);
+
+typedef enum {
+  Mark_flag_none = 0,
+  Mark_flag_input = 1 << 0,
+  Mark_flag_output = 1 << 1,
+  Mark_flag_haste_input = 1 << 2,
+  Mark_flag_lock = 1 << 3,
+  Mark_flag_sleep = 1 << 4,
+} Mark_flags;
+
+ORCA_OK_IF_UNUSED
+static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y,
+                               Usz x) {
+  (void)height;
+  return mbuf[y * width + x];
+}
+
+ORCA_OK_IF_UNUSED
+static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width,
+                                        Usz y, Usz x, Isz offs_y, Isz offs_x) {
+  Isz y0 = (Isz)y + offs_y;
+  Isz x0 = (Isz)x + offs_x;
+  if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0)
+    return Mark_flag_none;
+  return mbuf[(Usz)y0 * width + (Usz)x0];
+}
+
+ORCA_OK_IF_UNUSED
+static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y,
+                                  Usz x, Mark_flags flags) {
+  (void)height;
+  mbuf[y * width + x] |= (Mark)flags;
+}
+
+ORCA_OK_IF_UNUSED
+static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width,
+                                           Usz y, Usz x, Isz offs_y, Isz offs_x,
+                                           Mark_flags flags) {
+  Isz y0 = (Isz)y + offs_y;
+  Isz x0 = (Isz)x + offs_x;
+  if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0)
+    return;
+  mbuf[(Usz)y0 * width + (Usz)x0] |= (Mark)flags;
+}
+
+void mbuffer_clear(Mark* mbuf, Usz height, Usz width);
--- a/mark.c
+++ b/mark.c
@@ -14,8 +14,3 @@
 }
 
 void mbuf_reusable_deinit(Mbuf_reusable* mbr) { free(mbr->buffer); }
-
-void mbuffer_clear(Mark* mbuf, Usz height, Usz width) {
-  Usz cleared_size = height * width;
-  memset(mbuf, 0, cleared_size);
-}
--- a/mark.h
+++ b/mark.h
@@ -1,15 +1,6 @@
 #pragma once
 #include "base.h"
 
-typedef enum {
-  Mark_flag_none = 0,
-  Mark_flag_input = 1 << 0,
-  Mark_flag_output = 1 << 1,
-  Mark_flag_haste_input = 1 << 2,
-  Mark_flag_lock = 1 << 3,
-  Mark_flag_sleep = 1 << 4,
-} Mark_flags;
-
 typedef struct Mbuf_reusable {
   Mark* buffer;
   Usz capacity;
@@ -18,55 +9,3 @@
 void mbuf_reusable_init(Mbuf_reusable* mbr);
 void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width);
 void mbuf_reusable_deinit(Mbuf_reusable* mbr);
-
-void mbuffer_clear(Mark* mbuf, Usz height, Usz width);
-
-ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y, Usz x);
-ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width,
-                                        Usz y, Usz x, Isz offs_y, Isz offs_x);
-ORCA_OK_IF_UNUSED
-static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y,
-                                  Usz x, Mark_flags flags);
-ORCA_OK_IF_UNUSED
-static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width,
-                                           Usz y, Usz x, Isz offs_y, Isz offs_x,
-                                           Mark_flags flags);
-
-// Inline implementation
-
-ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y,
-                               Usz x) {
-  (void)height;
-  return mbuf[y * width + x];
-}
-
-ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width,
-                                        Usz y, Usz x, Isz offs_y, Isz offs_x) {
-  Isz y0 = (Isz)y + offs_y;
-  Isz x0 = (Isz)x + offs_x;
-  if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0)
-    return Mark_flag_none;
-  return mbuf[(Usz)y0 * width + (Usz)x0];
-}
-
-ORCA_OK_IF_UNUSED
-static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y,
-                                  Usz x, Mark_flags flags) {
-  (void)height;
-  mbuf[y * width + x] |= (Mark)flags;
-}
-
-ORCA_OK_IF_UNUSED
-static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width,
-                                           Usz y, Usz x, Isz offs_y, Isz offs_x,
-                                           Mark_flags flags) {
-  Isz y0 = (Isz)y + offs_y;
-  Isz x0 = (Isz)x + offs_x;
-  if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0)
-    return;
-  mbuf[(Usz)y0 * width + (Usz)x0] |= (Mark)flags;
-}
--- a/sim.c
+++ b/sim.c
@@ -1,6 +1,5 @@
 #include "sim.h"
 #include "gbuffer.h"
-#include "mark.h"
 
 //////// Utilities