ref: 47176077d8ba8fdedafc56c1f02c99ddba48d463
parent: a9e909fe0e23030d2d682e084b14df34bb52f55d
author: glenda <glenda@cirno>
date: Fri Mar 21 23:51:56 EDT 2025
refactor history
--- a/wind.c
+++ b/wind.c
@@ -21,33 +21,26 @@
if(nr <= 0)
return;
- s = runemalloc(nr);
- runemove(s, r, nr);
-
if(w->nhistory > 0 && nr == w->historylens[0] &&
- memcmp(s, w->history[0], nr*sizeof(Rune)) == 0) {
- free(s);
+ memcmp(r, w->history[0], nr*sizeof(Rune)) == 0)
return;
- }
+ s = runemalloc(nr);
+ runemove(s, r, nr);
+
if(w->nhistory == w->maxhistory) {
free(w->history[w->maxhistory-1]);
- w->nhistory--;
+ } else {
+ w->nhistory++;
}
- if(w->history == nil) {
- w->history = emalloc(w->maxhistory * sizeof(Rune*));
- w->historylens = emalloc(w->maxhistory * sizeof(int));
- }
-
- for(i = w->nhistory; i > 0; i--) {
+ for(i = w->nhistory-1; i > 0; i--) {
w->history[i] = w->history[i-1];
w->historylens[i] = w->historylens[i-1];
}
-
+
w->history[0] = s;
w->historylens[0] = nr;
- w->nhistory++;
w->histpos = -1;
}
@@ -1418,8 +1411,8 @@
Rectangle r;
w = emalloc(sizeof(Window));
- w->history = nil;
- w->historylens = nil;
+ w->history = emalloc(w->maxhistory * sizeof(Rune*));
+ w->historylens = emalloc(w->maxhistory * sizeof(int));
w->nhistory = 0;
w->maxhistory = 100;
w->histpos = -1;