Optimize.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16007 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-02-19 02:18:41 +00:00
parent 5faf6f6f1e
commit 6f8966e716
2 changed files with 27 additions and 16 deletions

View file

@ -1,3 +1,12 @@
2003-02-19 03:09 Alexander Malmberg <alexander@malmberg.org>
* Source/GSLayoutManager.m (-_glyphForCharacter:index:positions::):
Use binary search to find the index of the character in the run.
(-setLocation:forStartOfGlyphRange:): Start the search for the line
frag from the back, as the line frag we're searching will often
be the last one (always with GSHorizontalTypesetter).
2003-02-19 00:31 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSLayoutManager.h,

View file

@ -569,28 +569,31 @@ static glyph_run_t *run_insert(glyph_run_head_t **context)
{
glyph_run_t *r;
int pos, cpos;
int i;
int lo, hi, mid, i;
r = run_for_character_index(target, glyphs, &pos, &cpos);
if (!r)
return NULL;
i = 0;
if (r->glyphs[i].char_offset + cpos > target)
target -= cpos;
lo = 0;
hi = r->head.glyph_length - 1;
while (lo < hi)
{
GLYPH_SCAN_BACKWARD(r, i, pos, cpos, r->glyphs[i].char_offset + cpos > target)
}
else
{
GLYPH_SCAN_FORWARD(r, i, pos, cpos, r->glyphs[i].char_offset + cpos < target)
if (i == r->head.glyph_length)
GLYPH_STEP_BACKWARD(r, i, pos, cpos)
mid = (lo + hi) / 2;
if (r->glyphs[mid].char_offset > target)
hi = mid - 1;
else if (r->glyphs[mid].char_offset < target)
lo = mid + 1;
else
GLYPH_SCAN_BACKWARD(r, i, pos, cpos, r->glyphs[i].char_offset + cpos > target)
hi = lo;
}
target = r->glyphs[i].char_offset + cpos;
GLYPH_SCAN_BACKWARD(r, i, pos, cpos, r->glyphs[i].char_offset + cpos == target)
GLYPH_STEP_FORWARD(r, i, pos, cpos)
i = lo;
while (r->glyphs[i].char_offset > target)
i--;
while (i > 0 && r->glyphs[i - 1].char_offset == r->glyphs[i].char_offset)
i--;
*rindex = i;
*rpos = pos;
@ -1842,7 +1845,7 @@ forStartOfGlyphRange: (NSRange)glyphRange
return;
}
for (i = 0, lf = tc->linefrags; i < tc->num_linefrags; i++, lf++)
for (i = tc->num_linefrags - 1, lf = tc->linefrags + i; i >= 0; i--, lf--)
{
if (lf->pos <= glyphRange.location &&
lf->pos + lf->length >= glyphRange.location + glyphRange.length)
@ -1882,7 +1885,6 @@ forStartOfGlyphRange: (NSRange)glyphRange
lf->points = realloc(lf->points, sizeof(linefrag_point_t) * lf->num_points);
lp = &lf->points[lf->num_points - 1];
}
memset(lp, 0, sizeof(linefrag_point_t));
lp->pos = glyphRange.location;
lp->length = glyphRange.length;
lp->p = location;