Differences From Artifact [1da3535d97]:
- File
src/OFDate.m
— part of check-in
[a6ee2b2065]
at
2012-07-31 12:05:46
on branch trunk
— Slightly changed serialization format.
printf's %a was too fragile to serialize floats and doubles, as it was
behaving differently on different OSes and OS versions. Instead, a hex
representation of the float/double in big endian is used now. While this
is less readable, it is guaranteed to be accurate and always the same. (user: js, size: 13112) [annotate] [blame] [check-ins using]
To Artifact [91f4360e05]:
- File
src/OFDate.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: 13089) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
25 26 27 28 29 30 31 | #include <sys/time.h> #import "OFDate.h" #import "OFString.h" #import "OFDictionary.h" #import "OFXMLElement.h" | < > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <sys/time.h> #import "OFDate.h" #import "OFString.h" #import "OFDictionary.h" #import "OFXMLElement.h" #ifdef OF_THREADS # import "OFThread.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" #import "of_strptime.h" #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_THREADS) static OFMutex *mutex; #endif |
︙ | ︙ | |||
318 319 320 321 322 323 324 | } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { | | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); union { double d; uint64_t u; } d; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; d.u = (uint64_t)[element hexadecimalValue]; seconds = of_bswap_double_if_le(d.d); objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
409 410 411 412 413 414 415 | - (OFString*)description { return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } - (OFXMLElement*)XMLElementBySerializing { | | | | | | 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | - (OFString*)description { return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } - (OFXMLElement*)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; union { double d; uint64_t u; } d; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; d.d = of_bswap_double_if_le(seconds); [element setStringValue: [OFString stringWithFormat: @"%016" PRIx64, d.u]]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (uint32_t)microsecond { return (uint32_t)rint((seconds - floor(seconds)) * 1000000); } |
︙ | ︙ |