libdraw: avoid BPSHORT()/BPLONG() expansion, cleanup loadchar(),cachechars()
assigning the expression value to a temporary variable in BPSHORT() and BPLONG() saves arround 2K of text in rio on arm and arround 1K on amd64. loadchar(): use the passed in "h" as the char index instead of recomputing it from c-f->cache. dont recompute wid. cachechars(): do cache lookup and find oldest entry in a single loop pass.
This commit is contained in:
parent
6b989beb2f
commit
1787584ad8
3 changed files with 24 additions and 32 deletions
|
@ -512,10 +512,10 @@ extern int _cursorfd;
|
||||||
extern int _drawdebug; /* set to 1 to see errors from flushimage */
|
extern int _drawdebug; /* set to 1 to see errors from flushimage */
|
||||||
extern void _setdrawop(Display*, Drawop);
|
extern void _setdrawop(Display*, Drawop);
|
||||||
|
|
||||||
#define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
|
#define BGSHORT(p) ((p)[0]|((p)[1]<<8))
|
||||||
#define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
|
#define BGLONG(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
|
||||||
#define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
|
#define BPSHORT(p,v) do{ushort _v_=(v);(p)[0]=_v_;(p)[1]=_v_>>8;}while(0)
|
||||||
#define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
|
#define BPLONG(p,v) do{ulong _v_=(v);(p)[0]=_v_;(p)[1]=_v_>>8;(p)[2]=_v_>>16;(p)[3]=_v_>>24;}while(0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compressed image file parameters and helper routines
|
* Compressed image file parameters and helper routines
|
||||||
|
|
|
@ -505,10 +505,10 @@ extern int _cursorfd;
|
||||||
extern int _drawdebug; /* set to 1 to see errors from flushimage */
|
extern int _drawdebug; /* set to 1 to see errors from flushimage */
|
||||||
extern void _setdrawop(Display*, Drawop);
|
extern void _setdrawop(Display*, Drawop);
|
||||||
|
|
||||||
#define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
|
#define BGSHORT(p) ((p)[0]|((p)[1]<<8))
|
||||||
#define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
|
#define BGLONG(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
|
||||||
#define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
|
#define BPSHORT(p,v) do{ushort _v_=(v);(p)[0]=_v_;(p)[1]=_v_>>8;}while(0)
|
||||||
#define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
|
#define BPLONG(p,v) do{ulong _v_=(v);(p)[0]=_v_;(p)[1]=_v_>>8;(p)[2]=_v_>>16;(p)[3]=_v_>>24;}while(0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compressed image file parameters and helper routines
|
* Compressed image file parameters and helper routines
|
||||||
|
|
|
@ -10,7 +10,7 @@ static int fontresize(Font*, int, int, int);
|
||||||
int
|
int
|
||||||
cachechars(Font *f, char **ss, Rune **rr, ushort *cp, int max, int *wp, char **subfontname)
|
cachechars(Font *f, char **ss, Rune **rr, ushort *cp, int max, int *wp, char **subfontname)
|
||||||
{
|
{
|
||||||
int i, j, th, sh, h, w, rw, wid, nc;
|
int i, j, h, w, rw, wid, nc;
|
||||||
char *sp;
|
char *sp;
|
||||||
Rune r, *rp, vr;
|
Rune r, *rp, vr;
|
||||||
ulong a;
|
ulong a;
|
||||||
|
@ -41,32 +41,24 @@ cachechars(Font *f, char **ss, Rune **rr, ushort *cp, int max, int *wp, char **s
|
||||||
rw = 1;
|
rw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sh = (17 * (uint)r) & (f->ncache-NFLOOK-1);
|
a = ~0;
|
||||||
c = &f->cache[sh];
|
h = (17 * (uint)r) & (f->ncache-NFLOOK-1);
|
||||||
|
c = &f->cache[h];
|
||||||
|
tc = c;
|
||||||
ec = c+NFLOOK;
|
ec = c+NFLOOK;
|
||||||
h = sh;
|
|
||||||
while(c < ec){
|
while(c < ec){
|
||||||
if(c->value==r && c->age)
|
if(c->value==r && c->age)
|
||||||
goto Found;
|
goto Found;
|
||||||
|
if(c->age < a){
|
||||||
|
a = c->age;
|
||||||
|
tc = c;
|
||||||
|
}
|
||||||
c++;
|
c++;
|
||||||
h++;
|
h++;
|
||||||
}
|
}
|
||||||
|
/* Not found; use oldest entry */
|
||||||
/*
|
c = tc;
|
||||||
* Not found; toss out oldest entry
|
h = tc - f->cache;
|
||||||
*/
|
|
||||||
a = ~0;
|
|
||||||
th = sh;
|
|
||||||
tc = &f->cache[th];
|
|
||||||
while(tc < ec){
|
|
||||||
if(tc->age < a){
|
|
||||||
a = tc->age;
|
|
||||||
h = th;
|
|
||||||
c = tc;
|
|
||||||
}
|
|
||||||
tc++;
|
|
||||||
th++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(a && (f->age-a)<500){ /* kicking out too recent; resize */
|
if(a && (f->age-a)<500){ /* kicking out too recent; resize */
|
||||||
nc = 2*(f->ncache-NFLOOK) + NFLOOK;
|
nc = 2*(f->ncache-NFLOOK) + NFLOOK;
|
||||||
|
@ -287,8 +279,6 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
||||||
/* c is still valid as didn't reallocate f->cache */
|
/* c is still valid as didn't reallocate f->cache */
|
||||||
}
|
}
|
||||||
c->value = r;
|
c->value = r;
|
||||||
top = fi->top + (f->ascent-subf->f->ascent);
|
|
||||||
bottom = fi->bottom + (f->ascent-subf->f->ascent);
|
|
||||||
c->width = fi->width;
|
c->width = fi->width;
|
||||||
c->x = h*f->width;
|
c->x = h*f->width;
|
||||||
c->left = fi->left;
|
c->left = fi->left;
|
||||||
|
@ -297,13 +287,15 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
||||||
b = bufimage(f->display, 37);
|
b = bufimage(f->display, 37);
|
||||||
if(b == nil)
|
if(b == nil)
|
||||||
return 0;
|
return 0;
|
||||||
|
top = fi->top + (f->ascent-subf->f->ascent);
|
||||||
|
bottom = fi->bottom + (f->ascent-subf->f->ascent);
|
||||||
b[0] = 'l';
|
b[0] = 'l';
|
||||||
BPLONG(b+1, f->cacheimage->id);
|
BPLONG(b+1, f->cacheimage->id);
|
||||||
BPLONG(b+5, subf->f->bits->id);
|
BPLONG(b+5, subf->f->bits->id);
|
||||||
BPSHORT(b+9, c-f->cache);
|
BPSHORT(b+9, h);
|
||||||
BPLONG(b+11, c->x);
|
BPLONG(b+11, c->x);
|
||||||
BPLONG(b+15, top);
|
BPLONG(b+15, top);
|
||||||
BPLONG(b+19, c->x+((fi+1)->x-fi->x));
|
BPLONG(b+19, c->x+wid);
|
||||||
BPLONG(b+23, bottom);
|
BPLONG(b+23, bottom);
|
||||||
BPLONG(b+27, fi->x);
|
BPLONG(b+27, fi->x);
|
||||||
BPLONG(b+31, fi->top);
|
BPLONG(b+31, fi->top);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue