Revision: 25403
http://sourceforge.net/p/bibdesk/svn/25403
Author: hofman
Date: 2021-01-15 17:22:41 +0000 (Fri, 15 Jan 2021)
Log Message:
-----------
Use struct in an NSMapTable for document description of PDF icons, no need for
a separate class
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
Removed Paths:
-------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2021-01-15
15:19:19 UTC (rev 25402)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2021-01-15
17:22:41 UTC (rev 25403)
@@ -42,11 +42,19 @@
#import "_FVMappedDataProvider.h"
#import "_FVSplitSet.h"
-#import "_FVDocumentDescription.h"
+// This struct enables instantation of an icon entirely from pre-cached
objects, so it is no longer necessary to load the document just to figure out
the size and number of pages.
+typedef struct __FVDocumentDescription {
+ size_t _pageCount;
+ NSSize _fullSize;
+ BOOL _isLocked;
+} _FVDocumentDescription;
+
static pthread_mutex_t _releaseLock;
static _FVSplitSet *_releaseableIcons = nil;
static CGLayerRef _pageLayer = NULL;
+static NSMapTable *_documentDescriptions = nil;
+static pthread_mutex_t _descriptionLock;
@implementation FVPDFIcon
@@ -59,6 +67,9 @@
unsigned char split = [_FVMappedDataProvider maxProviderCount] / 2 - 1;
_releaseableIcons = [[_FVSplitSet allocWithZone:[self zone]]
initWithSplit:split];
+ pthread_mutex_init(&_descriptionLock, NULL);
+ _documentDescriptions = NSCreateMapTable(NSObjectMapKeyCallBacks,
NSOwnedPointerMapValueCallBacks, 0);
+
const CGSize layerSize = { 1, 1 };
CGContextRef context =
[FVWindowGraphicsContextWithSize(NSSizeFromCGSize(layerSize)) graphicsPort];
_pageLayer = CGLayerCreateWithContext(context, layerSize, NULL);
@@ -330,13 +341,14 @@
if (NULL != _thumbnail) {
_thumbnailSize = FVCGImageSize(_thumbnail);
// retain since there's a possible race here if another thread
inserts a description (although multiple instances shouldn't be rendering for
the same cache key)
- _FVDocumentDescription *desc = [[_FVDocumentDescription
descriptionForKey:_cacheKey] retain];
+ pthread_mutex_lock(&_descriptionLock);
+ _FVDocumentDescription *desc = NSMapGet(_documentDescriptions,
_cacheKey);
+ pthread_mutex_unlock(&_descriptionLock);
if (desc) {
_pageCount = desc->_pageCount;
_fullSize = desc->_fullSize;
_isLocked = desc->_isLocked;
}
- [desc release];
NSParameterAssert(_thumbnailSize.width > 0 &&
_thumbnailSize.height > 0);
exitEarly = NO == FVShouldDrawFullImageWithThumbnailSize(size,
_thumbnailSize) && _pageCount > 0;
}
@@ -377,12 +389,13 @@
else
_fullSize = NSMakeSize(NSHeight(pageRect) * FVDefaultScale,
NSWidth(pageRect) * FVDefaultScale);
- _FVDocumentDescription *desc = [_FVDocumentDescription new];
+ _FVDocumentDescription *desc = NSZoneMalloc(NULL,
sizeof(_FVDocumentDescription));
desc->_pageCount = _pageCount;
desc->_fullSize = _fullSize;
desc->_isLocked = _isLocked;
- [_FVDocumentDescription setDescription:desc forKey:_cacheKey];
- [desc release];
+ pthread_mutex_lock(&_descriptionLock);
+ NSMapInsert(_documentDescriptions, _cacheKey, desc);
+ pthread_mutex_unlock(&_descriptionLock);
// scale appropriately; small PDF images, for instance, don't need
scaling
_thumbnailSize = _fullSize;
Modified:
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
===================================================================
---
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
2021-01-15 15:19:19 UTC (rev 25402)
+++
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
2021-01-15 17:22:41 UTC (rev 25403)
@@ -57,8 +57,6 @@
CEC48F2425B090ED00A2B40A /* FVLockBadge.h in Headers */ = {isa
= PBXBuildFile; fileRef = CEC48F2225B090ED00A2B40A /* FVLockBadge.h */; };
CEC9932D1072B6C50089F20D /* FVPreviewer.xib in Resources */ =
{isa = PBXBuildFile; fileRef = CEC9932C1072B6C50089F20D /* FVPreviewer.xib */;
};
CEFC19B10F693E8B00B2AEE6 /* FileView.h in Headers */ = {isa =
PBXBuildFile; fileRef = CEFC19B00F693E8B00B2AEE6 /* FileView.h */; settings =
{ATTRIBUTES = (Public, ); }; };
- CEFC1CF60F6AB84000B2AEE6 /* _FVDocumentDescription.h in Headers
*/ = {isa = PBXBuildFile; fileRef = CEFC1CE90F6AB84000B2AEE6 /*
_FVDocumentDescription.h */; };
- CEFC1CF70F6AB84000B2AEE6 /* _FVDocumentDescription.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CEFC1CEA0F6AB84000B2AEE6 /*
_FVDocumentDescription.m */; };
CEFC1CFC0F6AB84000B2AEE6 /* FVCacheFile.h in Headers */ = {isa
= PBXBuildFile; fileRef = CEFC1CEF0F6AB84000B2AEE6 /* FVCacheFile.h */; };
CEFC1CFD0F6AB84000B2AEE6 /* FVCacheFile.mm in Sources */ = {isa
= PBXBuildFile; fileRef = CEFC1CF00F6AB84000B2AEE6 /* FVCacheFile.mm */; };
CEFC1CFE0F6AB84000B2AEE6 /* FVCGColorSpaceDescription.h in
Headers */ = {isa = PBXBuildFile; fileRef = CEFC1CF10F6AB84000B2AEE6 /*
FVCGColorSpaceDescription.h */; };
@@ -213,8 +211,6 @@
CEC48F2225B090ED00A2B40A /* FVLockBadge.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
FVLockBadge.h; sourceTree = "<group>"; };
CEC9932C1072B6C50089F20D /* FVPreviewer.xib */ = {isa =
PBXFileReference; lastKnownFileType = file.xib; path = FVPreviewer.xib;
sourceTree = "<group>"; };
CEFC19B00F693E8B00B2AEE6 /* FileView.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
FileView.h; sourceTree = "<group>"; };
- CEFC1CE90F6AB84000B2AEE6 /* _FVDocumentDescription.h */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path
= _FVDocumentDescription.h; sourceTree = "<group>"; };
- CEFC1CEA0F6AB84000B2AEE6 /* _FVDocumentDescription.m */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc;
path = _FVDocumentDescription.m; sourceTree = "<group>"; };
CEFC1CEF0F6AB84000B2AEE6 /* FVCacheFile.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
FVCacheFile.h; sourceTree = "<group>"; };
CEFC1CF00F6AB84000B2AEE6 /* FVCacheFile.mm */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp;
path = FVCacheFile.mm; sourceTree = "<group>"; };
CEFC1CF10F6AB84000B2AEE6 /* FVCGColorSpaceDescription.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = FVCGColorSpaceDescription.h; sourceTree = "<group>"; };
@@ -465,8 +461,6 @@
CE05D48B0D7B38B20034C2A8 /* Caching */ = {
isa = PBXGroup;
children = (
- CEFC1CE90F6AB84000B2AEE6 /*
_FVDocumentDescription.h */,
- CEFC1CEA0F6AB84000B2AEE6 /*
_FVDocumentDescription.m */,
CE65FC580F72578D0089F9DC /*
_FVMappedDataProvider.h */,
CE65FC590F72578D0089F9DC /*
_FVMappedDataProvider.m */,
CE65FC5A0F72578D0089F9DC /* _FVSplitSet.h */,
@@ -643,7 +637,6 @@
CE89233E0D7CBB19006D514C /* FVOperation.h in
Headers */,
CEA831140DC1FAB500B551D1 /*
FVAccessibilityIconElement.h in Headers */,
CEFC19B10F693E8B00B2AEE6 /* FileView.h in
Headers */,
- CEFC1CF60F6AB84000B2AEE6 /*
_FVDocumentDescription.h in Headers */,
CEFC1CFC0F6AB84000B2AEE6 /* FVCacheFile.h in
Headers */,
CEFC1CFE0F6AB84000B2AEE6 /*
FVCGColorSpaceDescription.h in Headers */,
CEFC1D000F6AB84000B2AEE6 /*
FVCGImageDescription.h in Headers */,
@@ -807,7 +800,6 @@
CE89233D0D7CBB18006D514C /*
FVInvocationOperation.m in Sources */,
CE89233F0D7CBB1A006D514C /* FVOperation.m in
Sources */,
CEA831150DC1FAB500B551D1 /*
FVAccessibilityIconElement.m in Sources */,
- CEFC1CF70F6AB84000B2AEE6 /*
_FVDocumentDescription.m in Sources */,
CEFC1CFD0F6AB84000B2AEE6 /* FVCacheFile.mm in
Sources */,
CEFC1CFF0F6AB84000B2AEE6 /*
FVCGColorSpaceDescription.m in Sources */,
CEFC1D010F6AB84000B2AEE6 /*
FVCGImageDescription.m in Sources */,
Deleted: trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.h
2021-01-15 15:19:19 UTC (rev 25402)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.h
2021-01-15 17:22:41 UTC (rev 25403)
@@ -1,64 +0,0 @@
-//
-// _FVDocumentDescription.h
-// FileView
-//
-// Created by Adam Maxwell on 07/15/08.
-/*
- This software is Copyright (c) 2008-2021
- Adam Maxwell. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
- - Neither the name of Adam Maxwell nor the names of any
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <Cocoa/Cocoa.h>
-#import "FVObject.h"
-
-/** @internal @brief Cached document attributes.
-
- This object enables instantation of an icon entirely from pre-cached objects,
so it is no longer necessary to load the document just to figure out the size
and number of pages. This is mainly intended for use with PDF/PS documents,
which can be expensive to open and parse. */
-@interface _FVDocumentDescription : FVObject {
-@public
- size_t _pageCount;
- NSSize _fullSize;
- BOOL _isLocked;
-}
-
-/** @internal @brief Get a description for a previously stored key.
-
- @param aKey A key object conforming to <NSCopying>
- @return A description or nil if not previously stored. */
-+ (_FVDocumentDescription *)descriptionForKey:(id)aKey;
-
-/** @internal @brief Cache a description for the given key.
-
- @param description A document description object
- @param aKey A key object conforming to <NSCopying>. */
-+ (void)setDescription:(_FVDocumentDescription *)description forKey:(id
<NSObject, NSCopying>)aKey;
-
-@end
Deleted: trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.m
2021-01-15 15:19:19 UTC (rev 25402)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVDocumentDescription.m
2021-01-15 17:22:41 UTC (rev 25403)
@@ -1,84 +0,0 @@
-//
-// _FVDocumentDescription.m
-// FileView
-//
-// Created by Adam Maxwell on 07/15/08.
-/*
- This software is Copyright (c) 2008-2021
- Adam Maxwell. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
- - Neither the name of Adam Maxwell nor the names of any
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "_FVDocumentDescription.h"
-#import <pthread.h>
-
-@implementation _FVDocumentDescription
-
-static NSMutableDictionary *_descriptionTable = nil;
-static pthread_mutex_t _descriptionLock;
-
-+ (void)initialize
-{
- FVINITIALIZE(_FVDocumentDescription);
- pthread_mutex_init(&_descriptionLock, NULL);
- _descriptionTable = [NSMutableDictionary new];
-}
-
-+ (_FVDocumentDescription *)descriptionForKey:(id)aKey;
-{
- NSParameterAssert(nil != aKey);
- _FVDocumentDescription *desc;
- pthread_mutex_lock(&_descriptionLock);
- desc = [_descriptionTable objectForKey:aKey];
- pthread_mutex_unlock(&_descriptionLock);
- return desc;
-}
-
-+ (void)setDescription:(_FVDocumentDescription *)description forKey:(id
<NSObject, NSCopying>)aKey;
-{
- NSParameterAssert(nil != description);
- NSParameterAssert(nil != aKey);
- pthread_mutex_lock(&_descriptionLock);
- [_descriptionTable setObject:description forKey:aKey];
- pthread_mutex_unlock(&_descriptionLock);
-}
-
-- (id)init
-{
- self = [super init];
- if (self) {
- _fullSize = NSZeroSize;
- _pageCount = 0;
- _isLocked = NO;
- }
- return self;
-}
-
-@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit