about summary refs log tree commit diff stats
path: root/src/teliva.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-01-25 20:53:46 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-01-25 20:53:46 -0800
commit2fc48626b5dcc83dcecb38eb1c0f230ef8f46710 (patch)
treed5d7f166fb2439b5565e11e6c1538d36949eff43 /src/teliva.c
parent2e38583da2f6db92ce375e08840ec3a1dae35549 (diff)
downloadteliva-2fc48626b5dcc83dcecb38eb1c0f230ef8f46710.tar.gz
optimization: stop saving identical definitions
This is long overdue.
Diffstat (limited to 'src/teliva.c')
-rw-r--r--src/teliva.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/teliva.c b/src/teliva.c
index 914842a..a08c90b 100644
--- a/src/teliva.c
+++ b/src/teliva.c
@@ -790,6 +790,13 @@ static void read_editor_buffer(char* out, int capacity) {
 
 static void update_definition(lua_State* L, const char* name, char* new_contents) {
   int oldtop = lua_gettop(L);
+  /* if contents are unmodified, return */
+  if (look_up_definition(L, name)) {
+    const char* old_contents = lua_tostring(L, -1);
+    bool contents_unmodified = (strcmp(old_contents, new_contents) == 0);
+    lua_settop(L, oldtop);
+    if (contents_unmodified) return;
+  }
   lua_getglobal(L, "teliva_program");
   int history_array = lua_gettop(L);
   /* create a new table containing a single binding */