Differences From Artifact [43de300ded]:
- File
src/OFCountedSet_hashtable.m
— part of check-in
[44f45c2e35]
at
2017-01-09 17:36:36
on branch trunk
— Update copyright
Forgot to add 2017, even though I already did quite some changes in
2017. (user: js, size: 4657) [annotate] [blame] [check-ins using]
To Artifact [b91174aa25]:
- File
src/OFCountedSet_hashtable.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 4665) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
32 33 34 35 36 37 38 | @implementation OFCountedSet_hashtable + (void)initialize { if (self == [OFCountedSet_hashtable class]) [self inheritMethodsFromClass: [OFMutableSet_hashtable class]]; } | | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | @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; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self addObject: object]; |
︙ | ︙ | |||
62 63 64 65 66 67 68 | [self release]; @throw e; } return self; } | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | [self release]; @throw e; } return self; } - initWithArray: (OFArray *)array { self = [self init]; @try { id const *objects = [array objects]; size_t count = [array count]; for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithObjects: (id const *)objects count: (size_t)count { self = [self init]; @try { for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; |
︙ | ︙ | |||
116 117 118 119 120 121 122 | [self release]; @throw e; } return self; } | | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement *)element { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: @"OFCountedSet"] || |
︙ | ︙ | |||
144 145 146 147 148 149 150 | count_ = [objectElement attributeForName: @"count"]; if (object == nil || count_ == nil) @throw [OFInvalidFormatException exception]; count = (size_t)[[count_ stringValue] decimalValue]; | | | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | count_ = [objectElement attributeForName: @"count"]; if (object == nil || count_ == nil) @throw [OFInvalidFormatException exception]; count = (size_t)[[count_ stringValue] decimalValue]; [_mapTable setObject: (void *)(uintptr_t)count forKey: [object objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @catch (id e) { |
︙ | ︙ | |||
187 188 189 190 191 192 193 | - (void)addObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (SIZE_MAX - count < 1 || UINTPTR_MAX - count < 1) @throw [OFOutOfRangeException exception]; | | | | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | - (void)addObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (SIZE_MAX - count < 1 || UINTPTR_MAX - count < 1) @throw [OFOutOfRangeException exception]; [_mapTable setObject: (void *)(uintptr_t)(count + 1) forKey: object]; } - (void)removeObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (count == 0) return; count--; if (count > 0) [_mapTable setObject: (void *)(uintptr_t)count forKey: object]; else [_mapTable removeObjectForKey: object]; } - (void)makeImmutable { } @end |