Differences From Artifact [8515c66c59]:
- File
src/OFObject.m
— part of check-in
[5337be0924]
at
2009-05-25 17:00:32
on branch trunk
— Improve objc_sync.m.
* Use inline functions to improve code readability.
* Fix a wrong lock.
* Initialize it in +[initialize] of OFObject. (user: js, size: 8240) [annotate] [blame] [check-ins using]
To Artifact [4147582b99]:
- File
src/OFObject.m
— part of check-in
[033054ad75]
at
2009-05-29 19:21:57
on branch trunk
— A few renames.
OFExceptions:
* OFNoMemException to OFOutOfMemoryException.
* OFMemNotPartOfObjException to OFMemoryNotPartOfObjectException.OFObject:
* -[addItemToMemoryPool:] to -[addMemoryToPool:].
* -[allocWithSize:] to -[allocMemoryWithSize:].
* -[allocNItems:withSize] to -[allocMemoryForNItems:withSize:].
* -[resizeMem:toSize] to -[resizeMemory:toSize:].
* -[resizeMem:toNItems:withSize:] to
-[resizeMemoryToNItems:withSize:].
* -[freeMem] to -[freeMemory:].OFString:
* -[urlencode] to -[urlEncodedString].
* -[urldecode] to -[urlDecodedString]. (user: js, size: 8338) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
193 194 195 196 197 198 199 | - (uint32_t)hash { /* Classes containing data should reimplement this! */ return (uint32_t)(intptr_t)self; } | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | 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 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | - (uint32_t)hash { /* Classes containing data should reimplement this! */ return (uint32_t)(intptr_t)self; } - addMemoryToPool: (void*)ptr { void **memchunks; size_t memchunks_size; memchunks_size = PRE_IVAR->memchunks_size + 1; if (SIZE_MAX - PRE_IVAR->memchunks_size < 1 || memchunks_size > SIZE_MAX / sizeof(void*)) @throw [OFOutOfRangeException newWithClass: isa]; if ((memchunks = realloc(PRE_IVAR->memchunks, memchunks_size * sizeof(void*))) == NULL) @throw [OFOutOfMemoryException newWithClass: isa andSize: memchunks_size]; PRE_IVAR->memchunks = memchunks; PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr; PRE_IVAR->memchunks_size = memchunks_size; return self; } - (void*)allocMemoryWithSize: (size_t)size { void *ptr, **memchunks; size_t memchunks_size; if (size == 0) return NULL; memchunks_size = PRE_IVAR->memchunks_size + 1; if (SIZE_MAX - PRE_IVAR->memchunks_size == 0 || memchunks_size > SIZE_MAX / sizeof(void*)) @throw [OFOutOfRangeException newWithClass: isa]; if ((ptr = malloc(size)) == NULL) @throw [OFOutOfMemoryException newWithClass: isa andSize: size]; if ((memchunks = realloc(PRE_IVAR->memchunks, memchunks_size * sizeof(void*))) == NULL) { free(ptr); @throw [OFOutOfMemoryException newWithClass: isa andSize: memchunks_size]; } PRE_IVAR->memchunks = memchunks; PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr; PRE_IVAR->memchunks_size = memchunks_size; return ptr; } - (void*)allocMemoryForNItems: (size_t)nitems withSize: (size_t)size { if (nitems == 0 || size == 0) return NULL; if (nitems > SIZE_MAX / size) @throw [OFOutOfRangeException newWithClass: isa]; return [self allocMemoryWithSize: nitems * size]; } - (void*)resizeMemory: (void*)ptr toSize: (size_t)size { void **iter; if (ptr == NULL) return [self allocMemoryWithSize: size]; if (size == 0) { [self freeMemory: ptr]; return NULL; } iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size; while (iter-- > PRE_IVAR->memchunks) { if (OF_UNLIKELY(*iter == ptr)) { if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL)) @throw [OFOutOfMemoryException newWithClass: isa andSize: size]; *iter = ptr; return ptr; } } @throw [OFMemoryNotPartOfObjectException newWithClass: isa andPointer: ptr]; } - (void*)resizeMemory: (void*)ptr toNItems: (size_t)nitems withSize: (size_t)size { if (ptr == NULL) return [self allocMemoryForNItems: nitems withSize: size]; if (nitems == 0 || size == 0) { [self freeMemory: ptr]; return NULL; } if (nitems > SIZE_MAX / size) @throw [OFOutOfRangeException newWithClass: isa]; return [self resizeMemory: ptr toSize: nitems * size]; } - freeMemory: (void*)ptr; { void **iter, *last, **memchunks; size_t i, memchunks_size; iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size; i = PRE_IVAR->memchunks_size; |
︙ | ︙ | |||
352 353 354 355 356 357 358 | PRE_IVAR->memchunks[i] = last; PRE_IVAR->memchunks_size = memchunks_size; return self; } } | | | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | PRE_IVAR->memchunks[i] = last; PRE_IVAR->memchunks_size = memchunks_size; return self; } } @throw [OFMemoryNotPartOfObjectException newWithClass: isa andPointer: ptr]; } - retain { PRE_IVAR->retain_count++; return self; |
︙ | ︙ |