discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Performance patch for large texts


From: Frederic
Subject: Performance patch for large texts
Date: Fri, 18 May 2001 00:10:36 -0400

Hi,

I have been playing with Ink.app a little bit and in particular, I tried
to open the "readme.rtf" of Ted (http://www.nllgg.nl/Ted).
This rtf file is about 1meg on disk and contains some pictures.
The file is correctly opened, except embedded pictures which are
ignored.

But I also met some performance issues:
1. Open takes 59sec on my machine (Linux 2.4 Pentium II 350MHZ, 256mo)
2. Resizing the document window takes 40sec.

I attached a quick and dirty patch that improves a little bit the
performance:
1. Open: 16sec 
2. Resizing: 2sec 

Feel free to integrate/ignore/rework this patch.

Hope this helps, Frederic
diff -u -r core/gui/Headers/AppKit/NSStringDrawing.h 
ref/gui/Headers/AppKit/NSStringDrawing.h
--- core/gui/Headers/AppKit/NSStringDrawing.h   Thu May 17 22:52:35 2001
+++ ref/gui/Headers/AppKit/NSStringDrawing.h    Thu May 17 22:04:53 2001
@@ -57,10 +57,4 @@
 
 @end
 
-@interface NSAttributedString (GNUstep)
-
--(NSSize) sizeRange:(NSRange) aRange forString:(NSString*)string;
-
-@end
-
 #endif /* _GNUstep_H_NSStringDrawing */
diff -u -r core/gui/Headers/DPSClient/NSStringDrawing.h 
ref/gui/Headers/DPSClient/NSStringDrawing.h
--- core/gui/Headers/DPSClient/NSStringDrawing.h        Thu May 17 22:52:35 2001
+++ ref/gui/Headers/DPSClient/NSStringDrawing.h Thu May 17 22:04:53 2001
@@ -57,10 +57,4 @@
 
 @end
 
-@interface NSAttributedString (GNUstep)
-
--(NSSize) sizeRange:(NSRange) aRange forString:(NSString*)string;
-
-@end
-
 #endif /* _GNUstep_H_NSStringDrawing */
diff -u -r core/gui/Headers/gnustep/gui/NSStringDrawing.h 
ref/gui/Headers/gnustep/gui/NSStringDrawing.h
--- core/gui/Headers/gnustep/gui/NSStringDrawing.h      Thu May 17 22:52:35 2001
+++ ref/gui/Headers/gnustep/gui/NSStringDrawing.h       Thu May 17 22:04:53 2001
@@ -57,10 +57,4 @@
 
 @end
 
-@interface NSAttributedString (GNUstep)
-
--(NSSize) sizeRange:(NSRange) aRange forString:(NSString*)string;
-
-@end
-
 #endif /* _GNUstep_H_NSStringDrawing */
diff -u -r core/gui/Source/GSSimpleLayoutManager.m 
ref/gui/Source/GSSimpleLayoutManager.m
--- core/gui/Source/GSSimpleLayoutManager.m     Thu May 17 22:52:45 2001
+++ ref/gui/Source/GSSimpleLayoutManager.m      Thu May 17 22:05:00 2001
@@ -120,7 +120,6 @@
 - (NSRect) rectForCharacterIndex: (unsigned) index;
 - (NSRange) lineRangeForRect: (NSRect) aRect;
 - (NSSize) _sizeOfRange: (NSRange) range;
-- (NSSize) _sizeOfRange: (NSRange) range forString:(NSString*)allText;
 
 // return value is identical to the real line number
 - (int) lineLayoutIndexForGlyphIndex: (unsigned) anIndex;
@@ -564,15 +563,6 @@
   return [_textStorage sizeRange: aRange];
 }
 
-- (NSSize) _sizeOfRange: (NSRange)aRange forString:(NSString*)str
-{
-  if (!aRange.length || _textStorage == nil ||
-      NSMaxRange(aRange) > [_textStorage length])
-    return NSZeroSize;
-
-  return [_textStorage sizeRange: aRange forString:str];
-}
-
 - (unsigned) lineLayoutIndexForPoint: (NSPoint)point
 {
   int i;
@@ -1009,7 +999,7 @@
              // evaluate size of current word
              advanceSize = [self _sizeOfRange:
                                    NSMakeRange (currentStringRange.location + 
position,
-                                                currentStringRange.length) 
forString:allText];
+                                                currentStringRange.length)];
 
              // handle case where single word is broader than width
              // (buckle word)
@@ -1025,7 +1015,7 @@
                           lastVisibleCharIndex--)
                        {
                          currentSize = [self _sizeOfRange: NSMakeRange(
-                             startingLineCharIndex, lastVisibleCharIndex) 
forString:allText];
+                             startingLineCharIndex, lastVisibleCharIndex)];
                        }
                      isBuckled = NO;
                      usedLineRect.size = currentSize;
diff -u -r core/gui/Source/NSStringDrawing.m ref/gui/Source/NSStringDrawing.m
--- core/gui/Source/NSStringDrawing.m   Thu May 17 23:27:53 2001
+++ ref/gui/Source/NSStringDrawing.m    Thu May 17 22:05:01 2001
@@ -438,7 +438,7 @@
 }
 
 static void
-setupChunk(GSTextChunk *chunk, NSAttributedString *str, NSString* string, 
NSRange range,
+setupChunk(GSTextChunk *chunk, NSAttributedString *str, NSRange range,
        GSGlyphArray *g, GSTextChunk *last)
 {
   GSTextRun    *lastRun = 0;
@@ -446,12 +446,9 @@
   unsigned     start = range.location;
   unsigned     loc = start;
   unsigned     end = NSMaxRange(range);
+  NSString     *string = [str string];
   unichar      chars[range.length];
 
-       if ( string == nil )
-       {
-               string = [str string];
-       }
   [string getCharacters: chars range: range];
 
   /*
@@ -648,11 +645,11 @@
 }
 
 static GSTextChunk*
-setupLine(GSTextLine *line, NSAttributedString *str, NSString* asString, 
NSRange range,
+setupLine(GSTextLine *line, NSAttributedString *str, NSRange range,
        GSGlyphArray *g, NSParagraphStyle *style, float rMargin, BOOL first)
 {
   GSTextChunk  *lastChunk = 0;
-  NSString     *string = nil;
+  NSString     *string = [str string];
   NSArray      *tabs = [style tabStops];
   float                maxh = [style maximumLineHeight];
   unsigned     start = range.location;
@@ -660,14 +657,6 @@
   unsigned     numTabs = [tabs count];
   unsigned     nextTab = 0;
 
-       if ( asString != nil )
-       {
-               string = asString;
-       }
-       else
-       {
-               string = [str string];
-       }
   line->alignment = [style alignment];
   line->lineBreakMode = [style lineBreakMode];
   line->height = [style minimumLineHeight];
@@ -706,7 +695,7 @@
        */
       if (lastChunk == 0)
        {
-         setupChunk(&line->chunk0, str, string, chunkRange, g, 0);
+         setupChunk(&line->chunk0, str, chunkRange, g, 0);
          lastChunk = &line->chunk0;
        }
       else
@@ -714,7 +703,7 @@
          GSTextChunk   *chunk;
 
          chunk = (GSTextChunk*)objc_malloc(sizeof(GSTextChunk));
-         setupChunk(chunk, str, string, chunkRange, g, lastChunk);
+         setupChunk(chunk, str, chunkRange, g, lastChunk);
          lastChunk = chunk;
        }
 
@@ -955,7 +944,7 @@
            garray.size = line.length;
            garray.glyphs = info;
 
-           setupLine(&current, str, allText, line, &garray, style, width, YES);
+           setupLine(&current, str, line, &garray, style, width, YES);
            drawLine(&current, ctxt, point, isFlipped);
 
            if (isFlipped)
@@ -973,9 +962,9 @@
 }
 
 static NSSize
-sizeAttributedString(NSAttributedString *str, NSString* text, NSRange aRange)
+sizeAttributedString(NSAttributedString *str, NSRange aRange)
 {
-  NSString             *allText = text ? text : [str string];
+  NSString             *allText = [str string];
   unsigned             length = NSMaxRange(aRange);
   unsigned             paraPos = aRange.location;
   NSParagraphStyle     *style = nil;
@@ -1032,7 +1021,7 @@
            garray.used = 0;
            garray.glyphs = info;
 
-           setupLine(&current, str, allText, line, &garray, style, rMargin, 
YES);
+           setupLine(&current, str, line, &garray, style, rMargin, YES);
            if (current.width > size.width)
              size.width = current.width;
            size.height += current.height + current.leading;
@@ -1091,19 +1080,13 @@
 
 - (NSSize) size
 {
-  return sizeAttributedString(self, nil, NSMakeRange(0, [self length]));
+  return sizeAttributedString(self, NSMakeRange(0, [self length]));
 }
 
 // GNUstep extensions.
 - (NSSize) sizeRange: (NSRange) lineRange
 {
-  return sizeAttributedString(self, nil, lineRange);
-}
-
-// GNUstep extensions.
-- (NSSize) sizeRange: (NSRange) lineRange forString:(NSString*)str
-{
-  return sizeAttributedString(self, str, lineRange);
+  return sizeAttributedString(self, lineRange);
 }
 
 - (void) drawRange: (NSRange) lineRange atPoint: (NSPoint) point

reply via email to

[Prev in Thread] Current Thread [Next in Thread]