Overview
Comment: | Cache the number of items in an OFList. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
768108a96074192fdbbd96db09567157 |
User & Date: | js on 2009-08-27 20:40:01 |
Other Links: | manifest | tags |
Context
2009-08-28
| ||
00:05 | Add OF_BSWAP{16,32,64}. check-in: c38fc9bb14 user: js tags: trunk | |
2009-08-27
| ||
20:40 | Cache the number of items in an OFList. check-in: 768108a960 user: js tags: trunk | |
17:52 | Add -[removeCharactersFromIndex:toIndex:] to OFMutableString. check-in: a9ff126697 user: js tags: trunk | |
Changes
Modified src/OFList.h from [493af3623a] to [03977d0bbb].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * The OFList class provides easy to use double-linked lists. */ @interface OFList: OFObject <OFCopying> { of_list_object_t *first; of_list_object_t *last; size_t listobj_size; BOOL retain_and_release; } /** * \return A new autoreleased OFList */ + list; | > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * The OFList class provides easy to use double-linked lists. */ @interface OFList: OFObject <OFCopying> { of_list_object_t *first; of_list_object_t *last; size_t listobj_size; size_t count; BOOL retain_and_release; } /** * \return A new autoreleased OFList */ + list; |
︙ | ︙ | |||
120 121 122 123 124 125 126 | * Removes the object with the specified list object from the list. * * \param listobj The list object returned by append / prepend */ - remove: (of_list_object_t*)listobj; /** | < < < | 121 122 123 124 125 126 127 128 129 130 131 | * Removes the object with the specified list object from the list. * * \param listobj The list object returned by append / prepend */ - remove: (of_list_object_t*)listobj; /** * \return The number of items in the list. */ - (size_t)count; @end |
Modified src/OFList.m from [ca08344bc3] to [3dcb760b24].
︙ | ︙ | |||
92 93 94 95 96 97 98 99 100 101 102 103 104 105 | if (last != NULL) last->next = o; last = o; if (first == NULL) first = o; if (retain_and_release) [obj retain]; return o; } | > > | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | if (last != NULL) last->next = o; last = o; if (first == NULL) first = o; count++; if (retain_and_release) [obj retain]; return o; } |
︙ | ︙ | |||
114 115 116 117 118 119 120 121 122 123 124 125 126 127 | if (first != NULL) first->prev = o; first = o; if (last == NULL) last = o; if (retain_and_release) [obj retain]; return o; } | > > | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | if (first != NULL) first->prev = o; first = o; if (last == NULL) last = o; count++; if (retain_and_release) [obj retain]; return o; } |
︙ | ︙ | |||
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | if (listobj->prev != NULL) listobj->prev->next = o; listobj->prev = o; if (listobj == first) first = o; if (retain_and_release) [obj retain]; return o; } | > > | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | if (listobj->prev != NULL) listobj->prev->next = o; listobj->prev = o; if (listobj == first) first = o; count++; if (retain_and_release) [obj retain]; return o; } |
︙ | ︙ | |||
162 163 164 165 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 192 193 194 195 196 197 | if (listobj->next != NULL) listobj->next->prev = o; listobj->next = o; if (listobj == last) last = o; if (retain_and_release) [obj retain]; return o; } - remove: (of_list_object_t*)listobj { if (listobj->prev != NULL) listobj->prev->next = listobj->next; if (listobj->next != NULL) listobj->next->prev = listobj->prev; if (first == listobj) first = listobj->next; if (last == listobj) last = listobj->prev; if (retain_and_release) [listobj->object release]; [self freeMemory: listobj]; return self; } - (size_t)count { | > > > > < < < < < < | | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 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 | if (listobj->next != NULL) listobj->next->prev = o; listobj->next = o; if (listobj == last) last = o; count++; if (retain_and_release) [obj retain]; return o; } - remove: (of_list_object_t*)listobj { if (listobj->prev != NULL) listobj->prev->next = listobj->next; if (listobj->next != NULL) listobj->next->prev = listobj->prev; if (first == listobj) first = listobj->next; if (last == listobj) last = listobj->prev; count--; if (retain_and_release) [listobj->object release]; [self freeMemory: listobj]; return self; } - (size_t)count { return count; } - (BOOL)isEqual: (id)obj { of_list_object_t *iter, *iter2; if (![obj isKindOfClass: [OFList class]]) |
︙ | ︙ | |||
243 244 245 246 247 248 249 250 251 252 253 254 255 256 | o->next = NULL; o->prev = prev; if (new->first == NULL) new->first = o; if (prev != NULL) prev->next = o; if (retain_and_release) [o->object retain]; prev = o; } } @catch (OFException *e) { [new release]; | > > > | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | o->next = NULL; o->prev = prev; if (new->first == NULL) new->first = o; if (prev != NULL) prev->next = o; new->count++; if (retain_and_release) [o->object retain]; prev = o; } } @catch (OFException *e) { [new release]; |
︙ | ︙ |
Modified tests/OFList/OFList.m from [0660a22302] to [c3c7e77f4a].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #ifndef _WIN32 #define ZD "%zd" #else #define ZD "%u" #endif | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #ifndef _WIN32 #define ZD "%zd" #else #define ZD "%u" #endif #define NUM_TESTS 27 #define SUCCESS \ { \ printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m", \ (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS); \ fflush(stdout); \ } #define FAIL \ |
︙ | ︙ | |||
85 86 87 88 89 90 91 92 93 94 95 96 97 98 | after: [list first]->next]; for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++) CHECK([iter->object isEqual: strings[j]]) CHECK([list count] == 3) list2 = [OFList list]; [list2 append: strings[0]]; [list2 append: strings[1]]; [list2 append: strings[2]]; CHECK([list2 isEqual: list]); | > > > > > > > > > | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | after: [list first]->next]; for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++) CHECK([iter->object isEqual: strings[j]]) CHECK([list count] == 3) list2 = [list copy]; CHECK([list2 count] == 3) [list2 remove: [list2 last]]; CHECK([list2 count] == 2) [list2 remove: [list2 first]->next]; CHECK([list2 count] == 1) [list2 remove: [list2 first]]; CHECK([list2 count] == 0) list2 = [OFList list]; [list2 append: strings[0]]; [list2 append: strings[1]]; [list2 append: strings[2]]; CHECK([list2 isEqual: list]); |
︙ | ︙ |