diff options
author | Kim Woelders <kim@woelders.dk> | 2021-12-19 22:59:42 +0100 |
---|---|---|
committer | Kim Woelders <kim@woelders.dk> | 2021-12-21 06:05:32 +0100 |
commit | b28d9110e4d083552d10104beb56b52f85e9d69a (patch) | |
tree | f607f3419df61312811de638e851f0a61442498e | |
parent | f9e0e92189b048610c6df06f07a7463dc21bcee2 (diff) | |
download | imlib2-b28d9110e4d083552d10104beb56b52f85e9d69a.tar.gz |
updates: Reduce memory usage
Apparently, sizeof(struct _tile) was 4 (gcc 11.2.1) ?!?
Weird - I think that once upon a time it was 1.
Anyway, avoid having ill defined struct size.
Also, simplify logic a bit (no need to deal with .usage as bit flags.
-rw-r--r-- | src/lib/updates.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/lib/updates.c b/src/lib/updates.c index 2f55fe7..6f04cb0 100644 --- a/src/lib/updates.c +++ b/src/lib/updates.c @@ -8,7 +8,7 @@ enum _t_used { }; struct _tile { - enum _t_used used; + char used; }; #define TBITS 5 @@ -23,7 +23,7 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax) { ImlibUpdate *nu = NULL, *uu; struct _tile *t; - int tw, th, x, y, i; + int tw, th, x, y; int *gaps = NULL; /* if theres no rects to process.. return NULL */ @@ -35,13 +35,7 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax) th = h >> TB; if (h & TM) th++; - t = malloc(tw * th * sizeof(struct _tile)); - /* fill in tiles to be all not used */ - for (i = 0, y = 0; y < th; y++) - { - for (x = 0; x < tw; x++) - t[i++].used = T_UNUSED; - } + t = calloc(tw * th, sizeof(struct _tile)); /* fill in all tiles */ for (uu = u; uu; uu = uu->next) { @@ -63,20 +57,20 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax) gaps[x] = 0; for (x = 0; x < tw; x++) { - if ((have) && (T(x, y).used == T_UNUSED)) + if (have && !T(x, y).used) { start = x; gap = 1; have = 0; } - else if ((!have) && (gap) && (T(x, y).used & T_USED)) + else if (!have && gap && T(x, y).used) { gap = 0; hgaps++; have = 1; gaps[start] = x - start; } - else if (T(x, y).used & T_USED) + else if (T(x, y).used) have = 1; } while (hgaps > hgapmax) @@ -95,8 +89,8 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax) if (start >= 0) { gaps[start] = 0; - for (x = start; - T(x, y).used == T_UNUSED; T(x++, y).used = T_USED); + for (x = start; !T(x, y).used; T(x++, y).used = T_USED) + ; hgaps--; } } @@ -107,19 +101,18 @@ __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax) { for (x = 0; x < tw; x++) { - if (T(x, y).used & T_USED) + if (T(x, y).used) { int xx, yy, ww, hh, ok, xww; - for (xx = x + 1, ww = 1; - (xx < tw) && (T(xx, y).used & T_USED); xx++, ww++); + for (xx = x + 1, ww = 1; xx < tw && T(xx, y).used; xx++, ww++) + ; xww = x + ww; - for (yy = y + 1, hh = 1, ok = 1; - (yy < th) && (ok); yy++, hh++) + for (yy = y + 1, hh = 1, ok = 1; yy < th && ok; yy++, hh++) { for (xx = x; xx < xww; xx++) { - if (!(T(xx, yy).used & T_USED)) + if (!T(xx, yy).used) { ok = 0; hh--; |