Differences From Artifact [b90b5a288c]:
- File src/OFCountedSet_hashtable.m — part of check-in [8892ae9fcc] at 2012-07-12 01:28:46 on branch trunk — Don't access isa directly. (user: js, size: 5196) [annotate] [blame] [check-ins using]
To Artifact [f28bc3a5ac]:
- File
src/OFCountedSet_hashtable.m
— part of check-in
[1255f3a11a]
at
2012-08-10 20:08:24
on branch trunk
— Directly use the runtime's autorelease pools.
This greatly improves performance, as it gets rid of the overhead of
OFAutoreleasePool. (user: js, size: 5155) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
22 23 24 25 26 27 28 | #import "OFCountedSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFString.h" #import "OFNumber.h" #import "OFArray.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" | < > > | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #import "OFCountedSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFString.h" #import "OFNumber.h" #import "OFArray.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "autorelease.h" @implementation OFCountedSet_hashtable + (void)initialize { if (self == [OFCountedSet_hashtable class]) [self inheritMethodsFromClass: [OFMutableSet_hashtable class]]; } - initWithSet: (OFSet*)set { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)countedSet; OFEnumerator *enumerator = [countedSet objectEnumerator]; id object; |
︙ | ︙ | |||
63 64 65 66 67 68 69 | OFEnumerator *enumerator = [set objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) [self addObject: object]; } | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | OFEnumerator *enumerator = [set objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) [self addObject: object]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
133 134 135 136 137 138 139 | } - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { | < | < < > | | | 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 186 187 | } - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); OFArray *objects; OFEnumerator *enumerator; OFXMLElement *objectElement; if (![[element name] isEqual: @"OFCountedSet"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; objects = [element elementsForName: @"object" namespace: OF_SERIALIZATION_NS]; enumerator = [objects objectEnumerator]; while ((objectElement = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; OFXMLAttribute *count; OFNumber *number; object = [[objectElement elementsForNamespace: OF_SERIALIZATION_NS] firstObject]; count = [objectElement attributeForName: @"count"]; if (object == nil || count == nil) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; number = [OFNumber numberWithSize: (size_t)[[count stringValue] decimalValue]]; [dictionary _setObject: number forKey: [object objectByDeserializing] copyKey: NO]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
201 202 203 204 205 206 207 | block(key, [object sizeValue], stop); }]; } #endif - (void)addObject: (id)object { | | | | | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | block(key, [object sizeValue], stop); }]; } #endif - (void)addObject: (id)object { void *pool = objc_autoreleasePoolPush(); OFNumber *count; count = [[dictionary objectForKey: object] numberByIncreasing]; if (count == nil) count = [OFNumber numberWithSize: 1]; [dictionary _setObject: count forKey: object copyKey: NO]; mutations++; objc_autoreleasePoolPop(pool); } - (void)removeObject: (id)object { OFNumber *count = [dictionary objectForKey: object]; void *pool; if (count == nil) return; pool = objc_autoreleasePoolPush(); count = [count numberByDecreasing]; if ([count sizeValue] > 0) [dictionary _setObject: count forKey: object copyKey: NO]; else [dictionary removeObjectForKey: object]; mutations++; objc_autoreleasePoolPop(pool); } - (void)makeImmutable { } @end |