mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Optimize -usedRectForTextContainer:.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19856 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8a4361bbae
commit
bc3d8f4913
3 changed files with 49 additions and 3 deletions
|
@ -1,3 +1,12 @@
|
|||
2004-08-09 21:45 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSLayoutManager_internal.h: Add
|
||||
usedRect and usedRectValid fields to textcontainer_t.
|
||||
* Source/GSLayoutManager.m (-_doLayout): Set usedRectValid to NO
|
||||
when setting complete to YES.
|
||||
(-usedRectForTextContainer:): Optimize the calculation of the used
|
||||
rect. Use usedRect and usedRectValid.
|
||||
|
||||
2004-08-09 14:38 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Headers/AppKit/NSWindow.h: _frame is the window frame.
|
||||
|
|
|
@ -193,6 +193,16 @@ typedef struct GSLayoutManager_textcontainer_s
|
|||
int num_linefrags;
|
||||
int num_soft;
|
||||
int size_linefrags;
|
||||
|
||||
/*
|
||||
Keep some per-textcontainer info that's expensive to calculate and often
|
||||
requested here.
|
||||
|
||||
According to profiling (2004-08-09), -usedRectForTextContainer: used to
|
||||
account for ~7% of execution time when editing huge files.
|
||||
*/
|
||||
NSRect usedRect;
|
||||
BOOL usedRectValid;
|
||||
} textcontainer_t;
|
||||
|
||||
|
||||
|
|
|
@ -1602,6 +1602,7 @@ places where we switch.
|
|||
break;
|
||||
}
|
||||
tc->complete = YES;
|
||||
tc->usedRectValid = NO;
|
||||
if (tc->num_soft)
|
||||
{
|
||||
/*
|
||||
|
@ -2197,10 +2198,36 @@ forStartOfGlyphRange: (NSRange)glyphRange
|
|||
|
||||
[self _doLayoutToContainer: i];
|
||||
tc = textcontainers + i;
|
||||
used = NSZeroRect;
|
||||
for (i = 0, lf = tc->linefrags; i < tc->num_linefrags; i++, lf++)
|
||||
used = NSUnionRect(used, lf->used_rect);
|
||||
|
||||
if (tc->usedRectValid)
|
||||
return tc->usedRect;
|
||||
|
||||
if (tc->num_linefrags)
|
||||
{
|
||||
double x0, y0, x1, y1;
|
||||
i = 0;
|
||||
lf = tc->linefrags;
|
||||
x0 = NSMinX(lf->used_rect);
|
||||
y0 = NSMinY(lf->used_rect);
|
||||
x1 = NSMaxX(lf->used_rect);
|
||||
y1 = NSMaxY(lf->used_rect);
|
||||
for (; i < tc->num_linefrags; i++, lf++)
|
||||
{
|
||||
if (NSMinX(lf->used_rect) < x0)
|
||||
x0 = NSMinX(lf->used_rect);
|
||||
if (NSMinY(lf->used_rect) < y0)
|
||||
y0 = NSMinY(lf->used_rect);
|
||||
if (NSMaxX(lf->used_rect) > x1)
|
||||
x1 = NSMinX(lf->used_rect);
|
||||
if (NSMaxY(lf->used_rect) > y1)
|
||||
y1 = NSMinY(lf->used_rect);
|
||||
}
|
||||
used = NSMakeRect(x0, y0, x1 - x0, y1 - y0);
|
||||
}
|
||||
else
|
||||
used = NSZeroRect;
|
||||
tc->usedRect = used;
|
||||
tc->usedRectValid = YES;
|
||||
return used;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue