Revision: 28520
http://sourceforge.net/p/bibdesk/svn/28520
Author: hofman
Date: 2024-01-03 16:55:34 +0000 (Wed, 03 Jan 2024)
Log Message:
-----------
reuse category function
Modified Paths:
--------------
trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m
Modified: trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m 2024-01-03 16:53:16 UTC
(rev 28519)
+++ trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m 2024-01-03 16:55:34 UTC
(rev 28520)
@@ -46,30 +46,8 @@
return CFStringCompare(item1, item2, kCFCompareCaseInsensitive |
kCFCompareNonliteral) == kCFCompareEqualTo;
}
-#define STACK_BUFFER_SIZE 256
-
static NSUInteger caseInsensitiveStringHash(const void *item, NSUInteger
(*size)(const void *item)) {
- if(item == NULL) return 0;
-
- NSUInteger hash = 0;
- CFAllocatorRef allocator = CFGetAllocator(item);
- CFIndex len = CFStringGetLength(item);
-
- // use a generous length, in case the lowercase changes the number of
characters
- UniChar *buffer, stackBuffer[STACK_BUFFER_SIZE];
- if (len + 10 >= STACK_BUFFER_SIZE)
- buffer = (UniChar *)CFAllocatorAllocate(allocator, (len + 10) *
sizeof(UniChar), 0);
- else
- buffer = stackBuffer;
- CFStringGetCharacters(item, CFRangeMake(0, len), buffer);
-
- // If we create the string with external characters,
CFStringGetCharactersPtr is guaranteed to succeed; since we're going to call
CFStringGetCharacters anyway in fastHash if CFStringGetCharactsPtr fails, let's
do it now when we lowercase the string
- CFMutableStringRef mutableString =
CFStringCreateMutableWithExternalCharactersNoCopy(allocator, buffer, len, len +
10, (buffer != stackBuffer ? allocator : kCFAllocatorNull));
- CFStringLowercase(mutableString, NULL);
- hash = CFHash(mutableString);//[(id)mutableString hash];
- // if we used the allocator, this should free the buffer for us
- CFRelease(mutableString);
- return hash;
+ return BDCaseInsensitiveStringHash(item);
}
static NSUInteger BibAuthorFuzzyHash(const void *item, NSUInteger
(*size)(const void *item))
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