Differences From Artifact [e987d561c5]:
- File src/OFString+Hashing.m — part of check-in [c1060114f6] at 2012-07-03 20:16:12 on branch trunk — OFHash: Take void* and unify convenience methods. (user: js, size: 2060) [annotate] [blame] [check-ins using]
To Artifact [c7fc790b94]:
- File
src/OFString+Hashing.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: 2047) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
15 16 17 18 19 20 21 | */ #include "config.h" #import "OFString.h" #import "OFMD5Hash.h" #import "OFSHA1Hash.h" | > | | | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | */ #include "config.h" #import "OFString.h" #import "OFMD5Hash.h" #import "OFSHA1Hash.h" #import "autorelease.h" int _OFString_Hashing_reference; @implementation OFString (Hashing) - (OFString*)MD5Hash { void *pool = objc_autoreleasePoolPush(); OFMD5Hash *hash = [OFMD5Hash hash]; uint8_t *digest; char ret[OF_MD5_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: [self UTF8String] length: [self UTF8StringLength]]; digest = [hash digest]; for (i = 0; i < OF_MD5_DIGEST_SIZE; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; ret[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); ret[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } objc_autoreleasePoolPop(pool); return [OFString stringWithCString: ret encoding: OF_STRING_ENCODING_ASCII length: 32]; } - (OFString*)SHA1Hash { void *pool = objc_autoreleasePoolPush(); OFMD5Hash *hash = [OFSHA1Hash hash]; uint8_t *digest; char ret[OF_SHA1_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: [self UTF8String] length: [self UTF8StringLength]]; digest = [hash digest]; for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; ret[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); ret[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } objc_autoreleasePoolPop(pool); return [OFString stringWithCString: ret encoding: OF_STRING_ENCODING_ASCII length: 40]; } @end |