mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
Save a little space and simplify code a little.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26473 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f5a87c292c
commit
01a7d37860
2 changed files with 90 additions and 60 deletions
|
@ -1,3 +1,9 @@
|
|||
2008-04-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSPropertyList.m:
|
||||
Use more memory efficient bitmaps for old style property list parsing
|
||||
where we know we are only using 8bit characters.
|
||||
|
||||
2008-03-20 David Chisnall <csdavec@swansea.ac.uk
|
||||
|
||||
* Source/NSObject.m: Changed atomic increment/decrement for intel
|
||||
|
|
|
@ -403,49 +403,99 @@ static id (*plAdd)(id, SEL, id) = 0;
|
|||
static Class plDictionary;
|
||||
static id (*plSet)(id, SEL, id, id) = 0;
|
||||
|
||||
/* Bitmap of 'quotable' characters ... those characters which must be
|
||||
* inside a quoted string if written to an old style property list.
|
||||
*/
|
||||
static const unsigned char quotables[32] = {
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\x85',
|
||||
'\x13',
|
||||
'\x00',
|
||||
'\x78',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x38',
|
||||
'\x01',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\xa8',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
'\xff',
|
||||
};
|
||||
|
||||
/* Bitmap of characters considered white space if in an old style property
|
||||
* list. This is the same as the set given by the isspace() function in the
|
||||
* POSIX locale, but (for cross-locale portability of property list files)
|
||||
* is fixed, rather than locale dependent.
|
||||
*/
|
||||
static const unsigned char whitespace[32] = {
|
||||
'\x00',
|
||||
'\x3f',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x01',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
'\x00',
|
||||
};
|
||||
|
||||
#define IS_BIT_SET(a,i) ((((a) & (1<<(i)))) > 0)
|
||||
|
||||
static unsigned const char *hexdigitsBitmapRep = NULL;
|
||||
#define GS_IS_HEXDIGIT(X) IS_BIT_SET(hexdigitsBitmapRep[(X)/8], (X) % 8)
|
||||
#define GS_IS_QUOTABLE(X) IS_BIT_SET(quotables[(X)/8], (X) % 8)
|
||||
|
||||
static void setupHexdigits(void)
|
||||
{
|
||||
if (hexdigitsBitmapRep == NULL)
|
||||
{
|
||||
NSCharacterSet *hexdigits;
|
||||
NSData *bitmap;
|
||||
#define GS_IS_WHITESPACE(X) IS_BIT_SET(whitespace[(X)/8], (X) % 8)
|
||||
|
||||
hexdigits = [NSCharacterSet characterSetWithCharactersInString:
|
||||
@"0123456789abcdefABCDEF"];
|
||||
bitmap = RETAIN([hexdigits bitmapRepresentation]);
|
||||
hexdigitsBitmapRep = [bitmap bytes];
|
||||
}
|
||||
}
|
||||
|
||||
static NSCharacterSet *quotables = nil;
|
||||
static NSCharacterSet *oldQuotables = nil;
|
||||
static NSCharacterSet *xmlQuotables = nil;
|
||||
|
||||
static unsigned const char *quotablesBitmapRep = NULL;
|
||||
#define GS_IS_QUOTABLE(X) IS_BIT_SET(quotablesBitmapRep[(X)/8], (X) % 8)
|
||||
|
||||
static void setupQuotables(void)
|
||||
{
|
||||
if (quotablesBitmapRep == NULL)
|
||||
if (oldQuotables == nil)
|
||||
{
|
||||
NSMutableCharacterSet *s;
|
||||
NSData *bitmap;
|
||||
|
||||
s = [[NSCharacterSet characterSetWithCharactersInString:
|
||||
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@"abcdefghijklmnopqrstuvwxyz!#$%&*+-./:?@|~_^"]
|
||||
mutableCopy];
|
||||
[s invert];
|
||||
quotables = [s copy];
|
||||
RELEASE(s);
|
||||
bitmap = RETAIN([quotables bitmapRepresentation]);
|
||||
quotablesBitmapRep = [bitmap bytes];
|
||||
s = [[NSCharacterSet characterSetWithCharactersInString:
|
||||
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@"abcdefghijklmnopqrstuvwxyz$./_"]
|
||||
|
@ -466,29 +516,6 @@ static void setupQuotables(void)
|
|||
}
|
||||
}
|
||||
|
||||
static unsigned const char *whitespaceBitmapRep = NULL;
|
||||
#define GS_IS_WHITESPACE(X) IS_BIT_SET(whitespaceBitmapRep[(X)/8], (X) % 8)
|
||||
|
||||
static void setupWhitespace(void)
|
||||
{
|
||||
if (whitespaceBitmapRep == NULL)
|
||||
{
|
||||
NSCharacterSet *whitespace;
|
||||
NSData *bitmap;
|
||||
|
||||
/*
|
||||
We can not use whitespaceAndNewlineCharacterSet here as this would lead
|
||||
to a recursion, as this also reads in a property list.
|
||||
whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
*/
|
||||
whitespace = [NSCharacterSet characterSetWithCharactersInString:
|
||||
@" \t\r\n\f\b"];
|
||||
|
||||
bitmap = RETAIN([whitespace bitmapRepresentation]);
|
||||
whitespaceBitmapRep = [bitmap bytes];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBXML
|
||||
#import "GNUstepBase/GSXML.h"
|
||||
static int XML_ELEMENT_NODE;
|
||||
|
@ -620,7 +647,7 @@ static inline id parseQuotedString(pldata* pld)
|
|||
}
|
||||
else if (escaped > 1)
|
||||
{
|
||||
if (hex && GS_IS_HEXDIGIT(c))
|
||||
if (hex && isxdigit(c))
|
||||
{
|
||||
shrink++;
|
||||
escaped++;
|
||||
|
@ -714,7 +741,7 @@ static inline id parseQuotedString(pldata* pld)
|
|||
}
|
||||
else if (escaped > 1)
|
||||
{
|
||||
if (hex && GS_IS_HEXDIGIT(c))
|
||||
if (hex && isxdigit(c))
|
||||
{
|
||||
chars[k] <<= 4;
|
||||
chars[k] |= char2num(c);
|
||||
|
@ -1089,8 +1116,8 @@ static id parsePlItem(pldata* pld)
|
|||
data = [[NSMutableData alloc] initWithCapacity: 0];
|
||||
skipSpace(pld);
|
||||
while (pld->pos < max
|
||||
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos])
|
||||
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos+1]))
|
||||
&& isxdigit(pld->ptr[pld->pos])
|
||||
&& isxdigit(pld->ptr[pld->pos+1]))
|
||||
{
|
||||
unsigned char byte;
|
||||
|
||||
|
@ -2401,10 +2428,7 @@ static BOOL classInitialized = NO;
|
|||
plSet = (id (*)(id, SEL, id, id))
|
||||
[plDictionary instanceMethodForSelector: @selector(setObject:forKey:)];
|
||||
|
||||
setupHexdigits();
|
||||
setupQuotables();
|
||||
setupWhitespace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue