Differences From Artifact [e16884bf15]:
- File src/OFAutoreleasePool.m — part of check-in [062a052b50] at 2010-04-17 15:46:34 on branch trunk — Don't return self where not necessary, return void or something useful. (user: js, size: 3473) [annotate] [blame] [check-ins using]
To Artifact [14bd700788]:
- File
src/OFAutoreleasePool.m
— part of check-in
[f92e1c77a0]
at
2010-07-08 09:20:54
on branch trunk
— Optimize OFAutoreleasePool.
It always allocates memory for 16 objects now. releaseObjects does not
free the memory allocated to store objects so that the same number of
objects can be stored in the autorelease pool again without the need to
allocate memory. This will give loops creating lots of objects a huge
performance boost. (user: js, size: 3837) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #import "OFAutoreleasePool.h" #import "OFArray.h" #import "OFExceptions.h" #ifdef OF_THREADS # import "threading.h" static of_tlskey_t first_key, last_key; #else static OFAutoreleasePool *first = nil, *last = nil; #endif @implementation OFAutoreleasePool | > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #import "OFAutoreleasePool.h" #import "OFArray.h" #import "OFExceptions.h" #ifdef OF_THREADS # import "threading.h" #define GROW_SIZE 16 static of_tlskey_t first_key, last_key; #else static OFAutoreleasePool *first = nil, *last = nil; #endif @implementation OFAutoreleasePool |
︙ | ︙ | |||
114 115 116 117 118 119 120 121 122 123 124 125 126 | #else first = self; #endif } if (prev != nil) prev->next = self; return self; } - (void)addObject: (OFObject*)obj { | > > > > > > > > > | | > > > | | | > > > > > | | > > > > > | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #else first = self; #endif } if (prev != nil) prev->next = self; size = GROW_SIZE; @try { objects = [self allocMemoryForNItems: GROW_SIZE withSize: sizeof(id)]; } @catch (OFException *e) { [self dealloc]; @throw e; } return self; } - (void)addObject: (OFObject*)obj { if (count + 1 > size) { objects = [self resizeMemory: objects toNItems: size + GROW_SIZE withSize: sizeof(id)]; size += GROW_SIZE; } objects[count] = obj; count++; } - (void)releaseObjects { size_t i; [next releaseObjects]; for (i = 0; i < count; i++) [objects[i] release]; count = 0; } - (void)release { [self dealloc]; } - (void)drain { [self dealloc]; } - (void)dealloc { size_t i; [next dealloc]; for (i = 0; i < count; i++) [objects[i] release]; /* * If of_tlskey_set fails, this is a real problem. The best we can do * is to not change the pool below the current pool and stop * deallocation. This way, new objects will be added to the current * pool, but released when the pool below gets released - and maybe * the pool itself will be released as well then, because maybe |
︙ | ︙ |