optimization: stop saving identical definitions

This is long overdue.
This commit is contained in:
Kartik K. Agaram 2022-01-25 20:53:46 -08:00
parent 2e38583da2
commit 2fc48626b5
1 changed files with 7 additions and 0 deletions

View File

@ -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 */