Overview
Comment: | Rename OFArray's and OFDataArray's -[data] to -[cArray]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2f1933eb24d27a6c9ddb377d234129d0 |
User & Date: | js on 2009-10-05 18:56:32 |
Other Links: | manifest | tags |
Context
2009-10-06
| ||
12:29 | Fix bug in decoding of lowercase «. check-in: 1882b31eec user: js tags: trunk | |
2009-10-05
| ||
18:56 | Rename OFArray's and OFDataArray's -[data] to -[cArray]. check-in: 2f1933eb24 user: js tags: trunk | |
2009-10-04
| ||
20:31 | Update PLATFORMS. check-in: b44adabc2e user: js tags: trunk | |
Changes
Modified src/OFArray.h from [eef3ed513f] to [d038bfa67f].
︙ | ︙ | |||
83 84 85 86 87 88 89 | * \return The number of objects in the OFArray */ - (size_t)count; /** * \return The objects of the array as a C array */ | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | * \return The number of objects in the OFArray */ - (size_t)count; /** * \return The objects of the array as a C array */ - (id*)cArray; /** * Returns a specific object of the OFDataArray. * * \param index The number of the object to return * \return The specified object of the OFArray */ |
︙ | ︙ |
Modified src/OFArray.m from [717e5d1c5c] to [04cd287505].
︙ | ︙ | |||
134 135 136 137 138 139 140 | } - (size_t)count { return [array count]; } | | | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | } - (size_t)count { return [array count]; } - (id*)cArray { return [array cArray]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFArray *new = [[OFMutableArray alloc] init]; OFObject **objs; size_t len, i; objs = [array cArray]; len = [array count]; [new->array addNItems: len fromCArray: objs]; for (i = 0; i < len; i++) [objs[i] retain]; |
︙ | ︙ | |||
188 189 190 191 192 193 194 | len = [array count]; len2 = [obj count]; if (len != len2) return NO; | | | | | 188 189 190 191 192 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 | len = [array count]; len2 = [obj count]; if (len != len2) return NO; objs = [array cArray]; objs2 = [obj cArray]; for (i = 0; i < len; i++) if (![objs[i] isEqual: objs2[i]]) return NO; return YES; } - (void)dealloc { OFObject **objs; size_t len, i; if (array != nil) { objs = [array cArray]; len = [array count]; for (i = 0; i < len; i++) [objs[i] release]; [array release]; } |
︙ | ︙ |
Modified src/OFDataArray.h from [2a3f92102e] to [8f9b91e500].
︙ | ︙ | |||
49 50 51 52 53 54 55 | /** * \return The size of each item in the OFDataArray in bytes */ - (size_t)itemsize; /** | | | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /** * \return The size of each item in the OFDataArray in bytes */ - (size_t)itemsize; /** * \return All elements of the OFDataArray as a C array */ - (void*)cArray; /** * Compares the OFDataArray to another object. * * \param obj An object to compare with * \return An integer which is the result of the comparison, see for example * strcmp |
︙ | ︙ |
Modified src/OFDataArray.m from [c9dcd66730] to [b0d6ba6983].
︙ | ︙ | |||
63 64 65 66 67 68 69 | } - (size_t)itemsize { return itemsize; } | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | } - (size_t)itemsize { return itemsize; } - (void*)cArray { return data; } - (void*)itemAtIndex: (size_t)index { if (index >= count) |
︙ | ︙ | |||
98 99 100 101 102 103 104 | withSize: itemsize]; memcpy(data + count++ * itemsize, item, itemsize); return self; } | | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | withSize: itemsize]; memcpy(data + count++ * itemsize, item, itemsize); return self; } - addNItems: (size_t)nitems fromCArray: (void*)carray { if (nitems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nitems withSize: itemsize]; |
︙ | ︙ | |||
143 144 145 146 147 148 149 | - (BOOL)isEqual: (id)obj { if (![obj isKindOfClass: [OFDataArray class]]) return NO; if ([obj count] != count || [obj itemsize] != itemsize) return NO; | | | | | | 143 144 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 | - (BOOL)isEqual: (id)obj { if (![obj isKindOfClass: [OFDataArray class]]) return NO; if ([obj count] != count || [obj itemsize] != itemsize) return NO; if (memcmp([obj cArray], data, count * itemsize)) return NO; return YES; } - (int)compare: (id)obj { int ret; if (![obj isKindOfClass: [OFDataArray class]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if ([obj itemsize] != itemsize) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if ([obj count] == count) return memcmp(data, [obj cArray], count * itemsize); if (count > [obj count]) { if ((ret = memcmp(data, [obj cArray], [obj count] * itemsize))) return ret; return *(char*)[self itemAtIndex: [obj count]]; } else { if ((ret = memcmp(data, [obj cArray], count * itemsize))) return ret; return *(char*)[obj itemAtIndex: count] * -1; } } - (uint32_t)hash |
︙ | ︙ |
Modified src/OFDictionary.m from [7f0d5a8891] to [bf06454e8f].
︙ | ︙ | |||
143 144 145 146 147 148 149 | return self; } - initWithObjects: (OFArray*)objs forKeys: (OFArray*)keys { | | | | | | 143 144 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 | return self; } - initWithObjects: (OFArray*)objs forKeys: (OFArray*)keys { id *objs_carray, *keys_carray; size_t objs_count, i; const SEL sel = @selector(setObject:forKey:); IMP set = [OFMutableDictionary instanceMethodForSelector: sel]; self = [self init]; objs_carray = [objs cArray]; keys_carray = [keys cArray]; objs_count = [objs count]; if (objs == nil || keys == nil || objs_count != [keys count]) { Class c = isa; [self dealloc]; @throw [OFInvalidArgumentException newWithClass: c selector: _cmd]; } @try { for (i = 0; i < objs_count; i++) set(self, sel, objs_carray[i], keys_carray[i]); } @catch (OFException *e) { [self dealloc]; @throw e; } return self; } |
︙ | ︙ |
Modified src/OFMutableArray.m from [a53f1d9b2e] to [770ad5f2bb].
︙ | ︙ | |||
17 18 19 20 21 22 23 | @implementation OFMutableArray - (id)copy { OFArray *new = [[OFArray alloc] init]; OFObject **objs; size_t len, i; | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | @implementation OFMutableArray - (id)copy { OFArray *new = [[OFArray alloc] init]; OFObject **objs; size_t len, i; objs = [array cArray]; len = [array count]; [new->array addNItems: len fromCArray: objs]; for (i = 0; i < len; i++) [objs[i] retain]; |
︙ | ︙ | |||
42 43 44 45 46 47 48 | } - removeNObjects: (size_t)nobjects { OFObject **objs; size_t len, i; | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | } - removeNObjects: (size_t)nobjects { OFObject **objs; size_t len, i; objs = [array cArray]; len = [array count]; if (nobjects > len) @throw [OFOutOfRangeException newWithClass: isa]; for (i = len - nobjects; i < len; i++) [objs[i] release]; [array removeNItems: nobjects]; return self; } @end |
Modified src/OFXMLElement.m from [5595432660] to [5f67a0c8ca].
︙ | ︙ | |||
119 120 121 122 123 124 125 | } - (OFString*)string { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; char *str_c; size_t len, i, j, attrs_count; | | | | | | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | } - (OFString*)string { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; char *str_c; size_t len, i, j, attrs_count; OFXMLAttribute **attrs_carray; OFString *ret, *tmp; len = [name cStringLength] + 4; str_c = [self allocMemoryWithSize: len]; /* Start of tag */ *str_c = '<'; memcpy(str_c + 1, [name cString], [name cStringLength]); i = [name cStringLength] + 1; /* Attributes */ attrs_carray = [attrs cArray]; attrs_count = [attrs count]; for (j = 0; j < attrs_count; j++) { /* FIXME: Add namespace support */ OFString *attr_name = [attrs_carray[j] name]; tmp = [[attrs_carray[j] stringValue] stringByXMLEscaping]; len += [attr_name cStringLength] + [tmp cStringLength] + 4; @try { str_c = [self resizeMemory: str_c toSize: len]; } @catch (OFException *e) { [self freeMemory: str_c]; |
︙ | ︙ | |||
166 167 168 169 170 171 172 | } /* Childen */ if (stringval != nil || children != nil) { if (stringval != nil) tmp = [stringval stringByXMLEscaping]; else if (children != nil) { | | | | | | 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 | } /* Childen */ if (stringval != nil || children != nil) { if (stringval != nil) tmp = [stringval stringByXMLEscaping]; else if (children != nil) { OFXMLElement **children_carray = [children cArray]; size_t children_count = [children count]; IMP append; tmp = [OFMutableString string]; append = [tmp methodForSelector: @selector(appendCStringWithoutUTF8Checking:)]; for (j = 0; j < children_count; j++) append(tmp, @selector( appendCStringWithoutUTF8Checking:), [[children_carray[j] string] cString]); } len += [tmp cStringLength] + [name cStringLength] + 2; @try { str_c = [self resizeMemory: str_c toSize: len]; } @catch (OFException *e) { |
︙ | ︙ |
Modified tests/dataarray.m from [8f9b25b225] to [77af06eab3].
︙ | ︙ | |||
50 51 52 53 54 55 56 | TEST(@"-[count]", [array[0] count] == 2) other = (class == [OFDataArray class] ? [OFBigDataArray class] : [OFDataArray class]); TEST(@"-[isEqual:]", (array[1] = [other dataArrayWithItemSize: 4096]) && [array[1] addNItems: [array[0] count] | | | | 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 | TEST(@"-[count]", [array[0] count] == 2) other = (class == [OFDataArray class] ? [OFBigDataArray class] : [OFDataArray class]); TEST(@"-[isEqual:]", (array[1] = [other dataArrayWithItemSize: 4096]) && [array[1] addNItems: [array[0] count] fromCArray: [array[0] cArray]] && [array[1] isEqual: array[0]] && [array[1] removeNItems: 1] && ![array[0] isEqual: array[1]]) TEST(@"-[copy]", (array[1] = [[array[0] copy] autorelease]) && [array[0] isEqual: array[1]]) TEST(@"-[compare]", [array[0] compare: array[1]] == 0 && [array[1] removeNItems: 1] && [array[0] compare: array[1]] == 0x42 && [array[1] compare: array[0]] == -0x42) TEST(@"-[hash]", [array[0] hash] == 0xC54621B6) TEST(@"-[removeNItems:]", [array[0] removeNItems: 1]) TEST(@"Building strings", (array[0] = [class dataArrayWithItemSize: 1]) && [array[0] addNItems: 6 fromCArray: (void*)str] && [array[0] addItem: ""] && !strcmp([array[0] cArray], str)) EXPECT_EXCEPTION(@"Detect out of range in -[itemAtIndex:]", OFOutOfRangeException, [array[0] itemAtIndex: [array[0] count]]) EXPECT_EXCEPTION(@"Detect out of range in -[addNItems:fromCArray:]", OFOutOfRangeException, [array[0] addNItems: SIZE_MAX fromCArray: NULL]) |
︙ | ︙ |
Modified tests/xmlparser.m from [6b442cb340] to [8f1d04dbb4].
︙ | ︙ | |||
31 32 33 34 35 36 37 | }; static void callback(enum event_type et, OFString *name, OFString *prefix, OFString *ns, OFArray *attrs, OFString *string, OFString *comment) { OFString *msg; | | | | | | | | | | | | | | | | | | | | | 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 86 87 88 89 90 91 92 93 94 95 96 97 | }; static void callback(enum event_type et, OFString *name, OFString *prefix, OFString *ns, OFArray *attrs, OFString *string, OFString *comment) { OFString *msg; id *carray; size_t count; i++; msg = [OFString stringWithFormat: @"Parsing part #%d", i]; switch (i) { case 1: case 5: TEST(msg, et == STRING && [string isEqual: @"bar"]) break; case 2: /* FIXME: Namespace */ carray = [attrs cArray]; count = [attrs count]; TEST(msg, et == TAG_START && [name isEqual: @"bar"] && [prefix isEqual: @"foo"] && ns == nil && attrs != nil && count == 2 && /* Attribute 1 */ [[carray[0] name] isEqual: @"bar"] && [carray[0] prefix] == nil && [[carray[0] stringValue] isEqual: @"b&az"] && [carray[0] namespace] == nil && /* Attribute 2 */ [[carray[1] name] isEqual: @"qux"] && [[carray[1] prefix] isEqual: @"qux"] && [[carray[1] stringValue] isEqual: @" quux "] && [carray[1] namespace] == nil) break; case 3: TEST(msg, et == STRING && [string isEqual: @"foo<bar"]) break; case 4: TEST(msg, et == TAG_START && [name isEqual: @"qux"] && prefix == nil && ns == nil) break; case 6: carray = [attrs cArray]; count = [attrs count]; TEST(msg, et == TAG_START && [name isEqual: @"baz"] && prefix == nil && ns == nil && attrs != nil && count == 2 && /* Attribute 1 */ [[carray[0] name] isEqual: @"name"] && [carray[0] prefix] == nil && [[carray[0] stringValue] isEqual: @""] && [carray[0] namespace] == nil && /* Attribute 2 */ [[carray[1] name] isEqual: @"test"] && [carray[1] prefix] == nil && [[carray[1] stringValue] isEqual: @"foobar"] && [carray[1] namespace] == nil) break; case 7: TEST(msg, et == TAG_END && [name isEqual: @"baz"] && prefix == nil && ns == nil) break; case 8: TEST(msg, et == STRING && [string isEqual: @"quxbar"]) |
︙ | ︙ |