diff --git a/ChangeLog b/ChangeLog index e2cec70f1..53fb58a71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2003-02-16 02:08 Alexander Malmberg +2003-02-17 02:16 Alexander Malmberg + + * Headers/gnustep/gui/GSLayoutManager.h, Source/GSLayoutManager.m: + Add some framework support for caching the last accessed run. + +2003-02-17 02:08 Alexander Malmberg * Source/NSLayoutManager.m (-rectArrayForGlyphRange: withinSelectedGlyphRange:inTextContainer:rectCount:, diff --git a/Headers/gnustep/gui/GSLayoutManager.h b/Headers/gnustep/gui/GSLayoutManager.h index acaa705b2..1ac5b4816 100644 --- a/Headers/gnustep/gui/GSLayoutManager.h +++ b/Headers/gnustep/gui/GSLayoutManager.h @@ -84,6 +84,15 @@ how it's supposed to work. It's functional and correct, but it isn't fast. */ /* For -rectArrayForGlyphRange:... */ NSRect *rect_array; int rect_array_size; + + + /* + Cached run. GSHorizontalTypesetter (and other typesetters, presumably) + often walk linearly through the glyphs. Thus, for many methods, we cache + the last run so we can quickly get more information for the next glyph. + */ + struct GSLayoutManager_glyph_run_s *cached_run; + int cached_pos, cached_cpos; } diff --git a/Source/GSLayoutManager.m b/Source/GSLayoutManager.m index bf4091ba6..f6e795440 100644 --- a/Source/GSLayoutManager.m +++ b/Source/GSLayoutManager.m @@ -191,6 +191,21 @@ glyph_run_t *GSLayoutManager_run_for_glyph_index(unsigned int glyphIndex, if (glyphs->glyph_length <= glyphIndex) return NULL; +#if 0 + if (cached_run) + { + if (glyphIndex >= cached_pos && + glyphIndex < cached_pos + cached_run->head.glyph_length) + { + if (glyph_pos) + *glyph_pos = cached_pos; + if (char_pos) + *char_pos = cached_cpos; + return cached_run; + } + } +#endif + pos = cpos = 0; level = SKIP_LIST_DEPTH; h = glyphs; @@ -223,6 +238,13 @@ glyph_run_t *GSLayoutManager_run_for_glyph_index(unsigned int glyphIndex, *glyph_pos = pos; if (char_pos) *char_pos = cpos; + +#if 0 + cached_run = (glyph_run_t *)h; + cached_pos = pos; + cached_cpos = cpos; +#endif + return (glyph_run_t *)h; } } @@ -900,6 +922,11 @@ it should still be safe. might lose opportunities to merge runs, though. NSRange rng; + /* + We always clear out the cached run information to be safe. + */ + cached_run = NULL; + /* [self _glyphDumpRuns]; printf("range=(%i+%i) lengthChange=%i\n", range.location, range.length, lengthChange);*/ range.length -= lengthChange;