Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -11,23 +11,16 @@ #include "config.h" #include #include -#include #include #import "OFDataArray.h" #import "OFExceptions.h" #import "macros.h" -#ifdef _WIN32 -#include -#endif - -static int lastpagebyte = 0; - @implementation OFDataArray + dataArrayWithItemSize: (size_t)is { return [[[self alloc] initWithItemSize: is] autorelease]; } @@ -267,36 +260,18 @@ return hash; } @end @implementation OFBigDataArray -- initWithItemSize: (size_t)is -{ - self = [super initWithItemSize: is]; - - if (lastpagebyte == 0) { -#ifndef _WIN32 - if ((lastpagebyte = sysconf(_SC_PAGESIZE)) == -1) - lastpagebyte = 4096; - lastpagebyte--; -#else - SYSTEM_INFO si; - GetSystemInfo(&si); - lastpagebyte = si.dwPageSize - 1; -#endif - } - - return self; -} - - addItem: (void*)item { - size_t nsize; + size_t nsize, lastpagebyte; if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; + lastpagebyte = of_pagesize - 1; nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; @@ -310,15 +285,16 @@ } - addNItems: (size_t)nitems fromCArray: (void*)carray { - size_t nsize; + size_t nsize, lastpagebyte; if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; + lastpagebyte = of_pagesize - 1; nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; @@ -333,15 +309,16 @@ - addNItems: (size_t)nitems fromCArray: (void*)carray atIndex: (size_t)index { - size_t nsize; + size_t nsize, lastpagebyte; if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; + lastpagebyte = of_pagesize - 1; nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toNItems: nsize @@ -357,16 +334,17 @@ return self; } - removeNItems: (size_t)nitems { - size_t nsize; + size_t nsize, lastpagebyte; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nitems; + lastpagebyte = of_pagesize - 1; nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; @@ -376,19 +354,20 @@ } - removeNItems: (size_t)nitems atIndex: (size_t)index { - size_t nsize; + size_t nsize, lastpagebyte; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemsize, data + (index + nitems) * itemsize, (count - index - nitems) * itemsize); count -= nitems; + lastpagebyte = of_pagesize - 1; nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -343,5 +343,7 @@ /** * \return A copy of the object */ - (id)mutableCopy; @end + +extern size_t of_pagesize; Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -12,10 +12,11 @@ #include "config.h" #include #include #include +#include #include #include #import "OFObject.h" #import "OFAutoreleasePool.h" @@ -27,10 +28,14 @@ # import #endif #ifdef OF_GNU_RUNTIME # import #endif + +#ifdef _WIN32 +# include +#endif #ifdef OF_ATOMIC_OPS # import "atomic.h" #else # import "threading.h" @@ -59,10 +64,12 @@ #define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN)) static struct { Class isa; } alloc_failed_exception; + +size_t of_pagesize; #ifdef NEED_OBJC_SYNC_INIT extern BOOL objc_sync_init(); #endif @@ -103,10 +110,19 @@ #endif #ifdef OF_APPLE_RUNTIME objc_setEnumerationMutationHandler(enumeration_mutation_handler); #endif + +#ifndef _WIN32 + if ((of_pagesize = sysconf(_SC_PAGESIZE)) < 1) + of_pagesize = 4096; +#else + SYSTEM_INFO si; + GetSystemInfo(&si); + of_pagesize = si.dwPageSize; +#endif } + (void)initialize { } Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -10,24 +10,17 @@ */ #include "config.h" #include -#include #include #import "OFStream.h" #import "OFString.h" #import "OFExceptions.h" #import "macros.h" -#ifdef _WIN32 -# include -#endif - -static int pagesize = 0; - @implementation OFStream - init { self = [super init]; @@ -35,22 +28,10 @@ @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; cache = NULL; -#ifndef _WIN32 - if (pagesize == 0) - if ((pagesize = sysconf(_SC_PAGESIZE)) == -1) - pagesize = 4096; -#else - if (pagesize == 0) { - SYSTEM_INFO si; - GetSystemInfo(&si); - pagesize = si.dwPageSize - 1; - } -#endif - return self; } - (BOOL)atEndOfStream { @@ -142,11 +123,11 @@ } } } /* Read until we get a newline or \0 */ - tmp = [self allocMemoryWithSize: pagesize]; + tmp = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { if ([self atEndOfStreamWithoutCache]) { if (cache == NULL) @@ -166,11 +147,11 @@ cache_len = 0; return ret; } - len = [self readNBytesWithoutCache: pagesize + len = [self readNBytesWithoutCache: of_pagesize intoBuffer: tmp]; /* Look if there's a newline or \0 */ for (i = 0; i < len; i++) { if (OF_UNLIKELY(tmp[i] == '\n' || @@ -283,11 +264,11 @@ } } } /* Read until we get the delimiter or \0 */ - tmp = [self allocMemoryWithSize: pagesize]; + tmp = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { if ([self atEndOfStreamWithoutCache]) { if (cache == NULL) @@ -302,11 +283,11 @@ cache_len = 0; return ret; } - len = [self readNBytesWithoutCache: pagesize + len = [self readNBytesWithoutCache: of_pagesize intoBuffer: tmp]; /* Look if there's the delimiter or \0 */ for (i = 0; i < len; i++) { if (tmp[i] != delim[j++])