Revision: 4864
http://skim-app.svn.sourceforge.net/skim-app/?rev=4864&view=rev
Author: hofman
Date: 2008-10-24 21:00:06 +0000 (Fri, 24 Oct 2008)
Log Message:
-----------
get length of pages only once
Modified Paths:
--------------
trunk/PDFSelection_SKExtensions.m
Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m 2008-10-24 16:41:07 UTC (rev 4863)
+++ trunk/PDFSelection_SKExtensions.m 2008-10-24 21:00:06 UTC (rev 4864)
@@ -394,6 +394,9 @@
NSEnumerator *specEnum = [specifier objectEnumerator];
NSScriptObjectSpecifier *spec;
+ unsigned int *pageLengths = NULL;
+ unsigned int numPages = 0;
+
while (spec = [specEnum nextObject]) {
if ([spec isKindOfClass:[NSScriptObjectSpecifier class]] == NO)
continue;
@@ -411,17 +414,18 @@
if ([container isKindOfClass:[SKPDFDocument class]] && (doc == nil
|| [doc isEqual:[container pdfDocument]])) {
PDFDocument *document = [container pdfDocument];
- unsigned int i, numPages = [document pageCount];
- unsigned int *pageLengths =
NSZoneMalloc(NSDefaultMallocZone(), numPages * sizeof(unsigned int));
- unsigned aPageIndex = aPage ? [aPage pageIndex] : NSNotFound;
+ unsigned int i, aPageIndex = aPage ? [aPage pageIndex] :
NSNotFound;
- for (i = 0; i < numPages; i++)
- pageLengths[i] = NSNotFound;
+ if (pageLengths == NULL) {
+ numPages = [document pageCount];
+ pageLengths = NSZoneMalloc(NSDefaultMallocZone(), numPages
* sizeof(unsigned int));
+ for (i = 0; i < numPages; i++)
+ pageLengths[i] = NSNotFound;
+ }
while (value = [rangeEnum nextObject]) {
NSRange range = [value rangeValue];
- unsigned int pageStart = 0;
- unsigned int startPage = NSNotFound, endPage = NSNotFound,
startIndex = NSNotFound, endIndex = NSNotFound;
+ unsigned int pageStart = 0, startPage = NSNotFound,
endPage = NSNotFound, startIndex = NSNotFound, endIndex = NSNotFound;
for (i = 0; i < numPages; i++) {
if (pageLengths[i] == NSNotFound)
@@ -450,8 +454,6 @@
}
}
- NSZoneFree(NSDefaultMallocZone(), pageLengths);
-
} else if ([container isKindOfClass:[PDFPage class]] && (aPage ==
nil || [aPage isEqual:container]) && (doc == nil || [doc isEqual:[container
document]])) {
while (value = [rangeEnum nextObject]) {
@@ -467,6 +469,9 @@
}
}
+ if (pageLengths)
+ NSZoneFree(NSDefaultMallocZone(), pageLengths);
+
PDFSelection *selection = nil;
if ([selections count]) {
selection = [selections objectAtIndex:0];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit