From aa8f8d866b54d5fd396d146e4f95b3c003d37602 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 10 Jan 2014 01:19:14 +0100 Subject: 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. --- sys/src/libdraw/stringwidth.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sys/src/libdraw/stringwidth.c') diff --git a/sys/src/libdraw/stringwidth.c b/sys/src/libdraw/stringwidth.c index 5fb4acaaa..f0757a095 100644 --- a/sys/src/libdraw/stringwidth.c +++ b/sys/src/libdraw/stringwidth.c @@ -22,6 +22,7 @@ _stringnwidth(Font *f, char *s, Rune *r, int len) rptr = nil; }else rptr = &r; + subfontname = nil; sf = nil; twid = 0; try = 0; @@ -29,17 +30,18 @@ _stringnwidth(Font *f, char *s, Rune *r, int len) 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 @@ _stringnwidth(Font *f, char *s, Rune *r, int len) continue; } try = 0; + agefont(f); twid += wid; len -= n; - - if(subfontname) - goto Nextfont; } freesubfont(sf); return twid; -- cgit v1.2.3