Differences From Artifact [9fd6867bb8]:
- File src/OFMutableDictionary.m — part of check-in [e84073d0f9] at 2010-08-29 17:53:56 on branch trunk — More methods using blocks. (user: js, size: 6172) [annotate] [blame] [check-ins using]
To Artifact [078edcac44]:
- File
src/OFMutableDictionary.m
— part of check-in
[e2b06423e0]
at
2010-09-05 23:19:08
on branch trunk
— Replace OFObject* with id in many places.
We assume now that every object understands retain, release, etc. so
that we can weaken the type from OFObject* to id. This makes it
possible to use different root object classes. (user: js, size: 6187) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
75 76 77 78 79 80 81 | } [self freeMemory: data]; data = newdata; size = newsize; } | | | | | | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | } [self freeMemory: data]; data = newdata; size = newsize; } - (void)setObject: (id)obj forKey: (id <OFCopying>)key { uint32_t i, hash, last; id old; if (key == nil || obj == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; hash = [(id)key hash]; last = size; for (i = hash & (size - 1); i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; if ([(id)data[i]->key isEqual: key]) break; } /* In case the last bucket is already used */ if (i >= last) { last = hash & (size - 1); for (i = 0; i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; if ([(id)data[i]->key isEqual: key]) break; } } /* Key not in dictionary */ if (i >= last || data[i] == NULL || data[i] == DELETED || ![(id)data[i]->key isEqual: key]) { BUCKET *b; [self _resizeForCount: count + 1]; mutations++; last = size; |
︙ | ︙ | |||
145 146 147 148 149 150 151 | [self freeMemory: b]; } @try { [obj retain]; } @catch (OFException *e) { [self freeMemory: b]; | | | | | | 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 188 189 190 191 192 193 | [self freeMemory: b]; } @try { [obj retain]; } @catch (OFException *e) { [self freeMemory: b]; [(id)key release]; @throw e; } b->key = key; b->object = obj; b->hash = hash; data[i] = b; count++; return; } old = data[i]->object; data[i]->object = [obj retain]; [old release]; } - (void)removeObjectForKey: (id)key { uint32_t i, hash, last; if (key == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; hash = [key hash]; last = size; for (i = hash & (size - 1); i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; if ([(id)data[i]->key isEqual: key]) { [(id)data[i]->key release]; [data[i]->object release]; [self freeMemory: data[i]]; data[i] = DELETED; count--; mutations++; [self _resizeForCount: count]; |
︙ | ︙ | |||
202 203 204 205 206 207 208 | /* In case the last bucket is already used */ last = hash & (size - 1); for (i = 0; i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; | | | | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | /* In case the last bucket is already used */ last = hash & (size - 1); for (i = 0; i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; if ([(id)data[i]->key isEqual: key]) { [(id)data[i]->key release]; [data[i]->object release]; [self freeMemory: data[i]]; data[i] = DELETED; count--; mutations++; [self _resizeForCount: count]; |
︙ | ︙ |