ref: aa8f8d866b54d5fd396d146e4f95b3c003d37602
parent: ce2487c3ccbad19322a38783e5af0ea398fc4243
author: cinap_lenrek <[email protected]>
date: Thu Jan 9 20:19:14 EST 2014
libdraw: cleanup string() and stringwidth() getting rid of the goto at the end of the while loop by moving the if(subfontnae) case before the cachechars() call.
--- a/sys/src/libdraw/string.c
+++ b/sys/src/libdraw/string.c
@@ -76,6 +76,7 @@
rptr = nil;
}else
rptr = &r;
+ subfontname = nil;
sf = nil;
try = 0;
while((*s || *r) && len > 0){
@@ -82,17 +83,18 @@
max = Max;
if(len < max)
max = len;
+ if(subfontname){
+ freesubfont(sf);
+ if((sf=_getsubfont(f->display, subfontname)) == nil){
+ if(f->display->defaultfont == nil || f->display->defaultfont == f)
+ break;
+ f = f->display->defaultfont;
+ }
+ }
if((n = cachechars(f, sptr, rptr, cbuf, max, &wid, &subfontname)) <= 0){
if(subfontname){
if(++try > 10)
break;
- Nextfont:
- freesubfont(sf);
- if((sf=_getsubfont(f->display, subfontname)) != nil)
- continue;
- if(f->display->defaultfont == nil || f->display->defaultfont == f)
- break;
- f = f->display->defaultfont;
continue;
}
if(*r)
@@ -144,9 +146,6 @@
bgp.x += wid;
agefont(f);
len -= n;
-
- if(subfontname)
- goto Nextfont;
}
freesubfont(sf);
return pt;
--- a/sys/src/libdraw/stringwidth.c
+++ b/sys/src/libdraw/stringwidth.c
@@ -22,6 +22,7 @@
rptr = nil;
}else
rptr = &r;
+ subfontname = nil;
sf = nil;
twid = 0;
try = 0;
@@ -29,17 +30,18 @@
max = Max;
if(len < max)
max = len;
+ if(subfontname){
+ freesubfont(sf);
+ if((sf=_getsubfont(f->display, subfontname)) == nil){
+ if(f->display == nil || f->display->defaultfont == nil || f->display->defaultfont == f)
+ break;
+ f = f->display->defaultfont;
+ }
+ }
if((n = cachechars(f, sptr, rptr, cbuf, max, &wid, &subfontname)) <= 0){
if(subfontname){
if(++try > 10)
break;
- Nextfont:
- freesubfont(sf);
- if((sf=_getsubfont(f->display, subfontname)) != nil)
- continue;
- if(f->display == nil || f->display->defaultfont == nil || f->display->defaultfont == f)
- break;
- f = f->display->defaultfont;
continue;
}
if(*r)
@@ -50,12 +52,10 @@
continue;
}
try = 0;
+
agefont(f);
twid += wid;
len -= n;
-
- if(subfontname)
- goto Nextfont;
}
freesubfont(sf);
return twid;