mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Additions for support of efficient NSArchiver/NSUnarchiver while permiting
ffective subclassing. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3107 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
12c5e09764
commit
95c9606271
2 changed files with 97 additions and 1 deletions
|
@ -94,6 +94,16 @@
|
|||
+ (id) dataWithShmID: (int)anID length: (unsigned) length;
|
||||
+ (id) dataWithSharedBytes: (const void*)bytes length: (unsigned) length;
|
||||
+ (id) dataWithStaticBytes: (const void*)bytes length: (unsigned) length;
|
||||
|
||||
/*
|
||||
* -deserializeTypeTagAtCursor:
|
||||
* -deserializeCrossRefAtCursor:
|
||||
* These methods are provided in order to give the GNUstep version of
|
||||
* NSUnarchiver maximum possible performance.
|
||||
*/
|
||||
- (unsigned char) deserializeTypeTagAtCursor: (unsigned*)cursor;
|
||||
- (unsigned) deserializeCrossRefAtCursor: (unsigned*)cursor;
|
||||
|
||||
/*
|
||||
* -initWithBytesNoCopy:length:fromZone:
|
||||
* The GNUstep designated initialiser for normal data objects - lets
|
||||
|
@ -169,9 +179,24 @@
|
|||
@end
|
||||
|
||||
@interface NSMutableData (GNUstepExtensions)
|
||||
/*
|
||||
* Capacity management - GNUstep gives you control over the size of
|
||||
* the data buffer as well as the 'length' of valid data in it.
|
||||
*/
|
||||
- (unsigned int) capacity;
|
||||
- (id) setCapacity: (unsigned int)newCapacity;
|
||||
- (int) shmID;
|
||||
|
||||
- (int) shmID; /* Shared memory ID for data buffer (if any) */
|
||||
|
||||
/*
|
||||
* -serializeTypeTag:
|
||||
* -serializeCrossRef:
|
||||
* These methods are provided in order to give the GNUstep version of
|
||||
* NSArchiver maximum possible performance.
|
||||
*/
|
||||
- (void) serializeTypeTag: (unsigned char)tag;
|
||||
- (void) serializeCrossRef: (unsigned)xref;
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
|
|
|
@ -934,6 +934,28 @@ failure:
|
|||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (unsigned char) deserializeTypeTagAtCursor: (unsigned*)cursor
|
||||
{
|
||||
unsigned char result;
|
||||
|
||||
[self deserializeDataAt: (void*)&result
|
||||
ofObjCType: @encode(unsigned char)
|
||||
atCursor: cursor
|
||||
context: nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (unsigned) deserializeCrossRefAtCursor: (unsigned*)cursor
|
||||
{
|
||||
unsigned result;
|
||||
|
||||
[self deserializeDataAt: (void*)&result
|
||||
ofObjCType: @encode(unsigned)
|
||||
atCursor: cursor
|
||||
context: nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void*) relinquishAllocatedBytes
|
||||
{
|
||||
return [self relinquishAllocatedBytesFromZone: 0];
|
||||
|
@ -1350,6 +1372,20 @@ failure:
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
- (void) serializeTypeTag: (unsigned char)tag
|
||||
{
|
||||
[self serializeDataAt: (void*)&tag
|
||||
ofObjCType: @encode(unsigned char)
|
||||
context: nil];
|
||||
}
|
||||
|
||||
- (void) serializeCrossRef: (unsigned)xref
|
||||
{
|
||||
[self serializeDataAt: (void*)&xref
|
||||
ofObjCType: @encode(unsigned)
|
||||
context: nil];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
@ -1671,6 +1707,23 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
}
|
||||
}
|
||||
|
||||
- (unsigned char) deserializeTypeTagAtCursor: (unsigned*)cursor
|
||||
{
|
||||
if (*cursor >= length) {
|
||||
[NSException raise: NSRangeException
|
||||
format: @"Range: (%u, 1) Size: %d", *cursor, length];
|
||||
}
|
||||
return ((unsigned char*)bytes)[(*cursor)++];
|
||||
}
|
||||
|
||||
- (unsigned) deserializeCrossRefAtCursor: (unsigned*)cursor
|
||||
{
|
||||
unsigned ni;
|
||||
|
||||
getBytes((void*)&ni, bytes, sizeof(ni), length, cursor);
|
||||
return (unsigned)NSSwapBigIntToHost(ni);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSDataMalloc
|
||||
|
@ -2406,6 +2459,24 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
}
|
||||
}
|
||||
|
||||
- (void) serializeTypeTag: (unsigned char)tag
|
||||
{
|
||||
if (length == capacity) {
|
||||
[self _grow: length + 1];
|
||||
}
|
||||
((unsigned char*)bytes)[length++] = tag;
|
||||
}
|
||||
|
||||
- (void) serializeCrossRef: (unsigned)xref
|
||||
{
|
||||
if (length + sizeof(unsigned) >= capacity) {
|
||||
[self _grow: length + sizeof(unsigned)];
|
||||
}
|
||||
xref = NSSwapHostIntToBig(xref);
|
||||
memcpy(bytes+length, &xref, sizeof(unsigned));
|
||||
length += sizeof(unsigned);
|
||||
}
|
||||
|
||||
- (id) setCapacity: (unsigned)size
|
||||
{
|
||||
if (size != capacity) {
|
||||
|
|
Loading…
Reference in a new issue