From 5faf6f6f1e0bfa800be560d23ddd5188933a4dee Mon Sep 17 00:00:00 2001 From: Alexander Malmberg Date: Tue, 18 Feb 2003 23:34:51 +0000 Subject: [PATCH] Optimize reuse of soft-invalidated layout a bit in a common case. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16006 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 +++ Headers/gnustep/gui/GSLayoutManager.h | 5 ++- .../gnustep/gui/GSLayoutManager_internal.h | 4 +- Source/GSHorizontalTypesetter.m | 20 ++++++++-- Source/GSLayoutManager.m | 38 +++++++++++++------ 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index e970c1141..4c81193a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-02-19 00:31 Alexander Malmberg + + * Headers/gnustep/gui/GSLayoutManager.h, + Source/GSHorizontalTypesetter.m, Source/GSLayoutManager.m: Optimize + reuse of soft-invalidated layout a bit in a common case. + 2003-02-19 00:10 Alexander Malmberg * Source/GSLayoutManager.m (-invalidateGlyphsForCharacterRange: diff --git a/Headers/gnustep/gui/GSLayoutManager.h b/Headers/gnustep/gui/GSLayoutManager.h index 5b24be4d7..9c9e9e198 100644 --- a/Headers/gnustep/gui/GSLayoutManager.h +++ b/Headers/gnustep/gui/GSLayoutManager.h @@ -1,10 +1,10 @@ /* GSLayoutManager.h - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Author: Alexander Malmberg - Date: 2002 + Date: November 2002 - February 2003 This file is part of the GNUstep GUI Library. @@ -329,6 +329,7 @@ layout information. nextGlyph: (unsigned int *)next_glyph inTextContainer: (NSTextContainer *)textContainer; -(unsigned int) _softInvalidateFirstGlyphInTextContainer: (NSTextContainer *)textContainer; +-(unsigned int) _softInvalidateNumberOfLineFragsInTextContainer: (NSTextContainer *)textContainer; @end diff --git a/Headers/gnustep/gui/GSLayoutManager_internal.h b/Headers/gnustep/gui/GSLayoutManager_internal.h index 11270675b..769be7a03 100644 --- a/Headers/gnustep/gui/GSLayoutManager_internal.h +++ b/Headers/gnustep/gui/GSLayoutManager_internal.h @@ -1,10 +1,10 @@ /* GSLayoutManager_internal.h - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Author: Alexander Malmberg - Date: 2002 + Date: November 2002 - February 2003 This file is part of the GNUstep GUI Library. diff --git a/Source/GSHorizontalTypesetter.m b/Source/GSHorizontalTypesetter.m index df2a3aae0..7ceb990e8 100644 --- a/Source/GSHorizontalTypesetter.m +++ b/Source/GSHorizontalTypesetter.m @@ -1,10 +1,10 @@ /* GSHorizontalTypesetter.m - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Author: Alexander Malmberg - Date: 2002 + Date: November 2002 - February 2003 This file is part of the GNUstep GUI Library. @@ -418,7 +418,21 @@ typedef struct GSHorizontalTypesetter_line_frag_s */ shift.width = 0; shift.height = curPoint.y - r0.origin.y; - for (i = 1; 1; i++) + if (shift.height == 0) + { + /* + If we don't need to shift, we know that everything will fit, + so we just need the last rectangle so we can update the + current point and glyph. + */ + i = [curLayoutManager _softInvalidateNumberOfLineFragsInTextContainer: curTextContainer]; + i--; + } + else + { + i = 1; + } + for (; 1; i++) { r = [curLayoutManager _softInvalidateLineFragRect: i nextGlyph: &g2 diff --git a/Source/GSLayoutManager.m b/Source/GSLayoutManager.m index 99b3f74d4..948b6b5ee 100644 --- a/Source/GSLayoutManager.m +++ b/Source/GSLayoutManager.m @@ -1,10 +1,10 @@ /* GSLayoutManager.m - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Author: Alexander Malmberg - Date: 2002 + Date: November 2002 - February 2003 This file is part of the GNUstep GUI Library. @@ -1164,9 +1164,7 @@ places where we switch. next->glyphs = NULL; } /* TODO: this creates really large runs at times */ - printf("at %i, length is %i, max is %i\n",cpos,next->head.char_length,max); next->head.char_length -= max - cpos; - printf("extend?? to %i\n",next->head.char_length); hn = &next->head; hn--; @@ -1213,7 +1211,7 @@ places where we switch. adjust their heads with updated information. When we're done, we update all the remaining heads. */ - printf("create runs for %i+%i\n", range.location, range.length); +// printf("create runs for %i+%i\n", range.location, range.length); { /* OPT: this is creating more runs than it needs to */ NSDictionary *attributes; glyph_run_t *new; @@ -2283,16 +2281,20 @@ forStartOfGlyphRange: (NSRange)glyphRange return; } - for (i = 0, lf = &tc->linefrags[tc->num_linefrags]; i < num; i++, lf++) + if (shift.width || shift.height) { - lf->rect.origin.x += shift.width; - lf->rect.origin.y += shift.height; - lf->used_rect.origin.x += shift.width; - lf->used_rect.origin.y += shift.height; - tc->length += lf->length; + for (i = 0, lf = &tc->linefrags[tc->num_linefrags]; i < num; i++, lf++) + { + lf->rect.origin.x += shift.width; + lf->rect.origin.y += shift.height; + lf->used_rect.origin.x += shift.width; + lf->used_rect.origin.y += shift.height; + } } tc->num_soft -= num; tc->num_linefrags += num; + lf = &tc->linefrags[tc->num_linefrags - 1]; + tc->length = lf->pos + lf->length - tc->pos; layout_glyph = tc->pos + tc->length; /* @@ -2347,6 +2349,20 @@ forStartOfGlyphRange: (NSRange)glyphRange return (unsigned int)-1; } +-(unsigned int) _softInvalidateNumberOfLineFragsInTextContainer: (NSTextContainer *)textContainer +{ + int i; + textcontainer_t *tc; + for (i = 0, tc = textcontainers; i < num_textcontainers; i++, tc++) + if (tc->textContainer == textContainer) + break; + if (i == num_textcontainers) + { + NSLog(@"(%s): does not own text container", __PRETTY_FUNCTION__); + return (unsigned int)-1; + } + return tc->num_soft; +} @end