Differences From Artifact [b7208d53f6]:
- File
src/OFNumber.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: 29087) [annotate] [blame] [check-ins using]
To Artifact [70f21d39ef]:
- File
src/OFNumber.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: 29064) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
18 19 20 21 22 23 24 | #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" | < > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "autorelease.h" #import "macros.h" #define RETURN_AS(t) \ switch (type) { \ case OF_NUMBER_BOOL: \ return (t)value.bool_; \ case OF_NUMBER_CHAR: \ |
︙ | ︙ | |||
715 716 717 718 719 720 721 | } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { | | | 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; |
︙ | ︙ | |||
772 773 774 775 776 777 778 | type = OF_NUMBER_DOUBLE; value.double_ = of_bswap_double_if_le(d.d); } else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; | | | 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | type = OF_NUMBER_DOUBLE; value.double_ = of_bswap_double_if_le(d.d); } else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
1207 1208 1209 1210 1211 1212 1213 | @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } } - (OFXMLElement*)XMLElementBySerializing { | | | 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } } - (OFXMLElement*)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS stringValue: [self description]]; switch (type) { |
︙ | ︙ | |||
1282 1283 1284 1285 1286 1287 1288 | break; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } [element retain]; | | | | | 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | break; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString*)JSONRepresentation { if (type == OF_NUMBER_BOOL) return (value.bool_ ? @"true" : @"false"); return [self description]; } @end |