CHAR_BITを使って書き直し。
@@ -34,6 +34,7 @@ | ||
34 | 34 | #define CSTL_SET_H_INCLUDED |
35 | 35 | |
36 | 36 | #include <stdlib.h> |
37 | +#include <limits.h> | |
37 | 38 | #include "common.h" |
38 | 39 | #include "rbtree.h" |
39 | 40 |
@@ -243,7 +244,6 @@ | ||
243 | 244 | {\ |
244 | 245 | CstlIterInternal i;\ |
245 | 246 | register size_t j = 0;\ |
246 | - register size_t idx = 0;\ | |
247 | 247 | size_t n;\ |
248 | 248 | unsigned char *insert_flags;\ |
249 | 249 | CSTL_ASSERT(self && "Set_assoc_insert_range");\ |
@@ -259,7 +259,7 @@ | ||
259 | 259 | }\ |
260 | 260 | }\ |
261 | 261 | if (!n) return 1;\ |
262 | - insert_flags = (unsigned char *) malloc(((n - 1) / 8) + 1);\ | |
262 | + insert_flags = (unsigned char *) malloc(((n - 1) / CHAR_BIT) + 1);\ | |
263 | 263 | if (!insert_flags) return 0;\ |
264 | 264 | for (i = first; CSTL_CAST_VPTR(Name, i.in_vptr)->ne(i.data, last.data); \ |
265 | 265 | CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), j++) {\ |
@@ -266,22 +266,16 @@ | ||
266 | 266 | int success;\ |
267 | 267 | if (Name##_set_insert(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->data(i.data), 0, &success)) {\ |
268 | 268 | if (success) {\ |
269 | - insert_flags[idx] |= (unsigned char)(1 << (j % 8));\ | |
269 | + insert_flags[j / CHAR_BIT] |= (unsigned char)(1 << (j % CHAR_BIT));\ | |
270 | 270 | } else {\ |
271 | - insert_flags[idx] &= ~(unsigned char)(1 << (j % 8));\ | |
271 | + insert_flags[j / CHAR_BIT] &= ~(unsigned char)(1 << (j % CHAR_BIT));\ | |
272 | 272 | }\ |
273 | - if ((j % 8) == 7) {\ | |
274 | - idx++;\ | |
275 | - }\ | |
276 | 273 | } else {\ |
277 | 274 | register size_t k;\ |
278 | - for (i = first, k = 0, idx = 0; k < j; CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), k++) {\ | |
279 | - if (insert_flags[idx] & (unsigned char)(1 << (k % 8))) {\ | |
275 | + for (i = first, k = 0; k < j; CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), k++) {\ | |
276 | + if (insert_flags[k / CHAR_BIT] & (unsigned char)(1 << (k % CHAR_BIT))) {\ | |
280 | 277 | Name##_erase_key(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->data(i.data));\ |
281 | 278 | }\ |
282 | - if ((k % 8) == 7) {\ | |
283 | - idx++;\ | |
284 | - }\ | |
285 | 279 | }\ |
286 | 280 | free(insert_flags);\ |
287 | 281 | return 0;\ |
@@ -34,6 +34,7 @@ | ||
34 | 34 | #define CSTL_MAP_H_INCLUDED |
35 | 35 | |
36 | 36 | #include <stdlib.h> |
37 | +#include <limits.h> | |
37 | 38 | #include "common.h" |
38 | 39 | #include "rbtree.h" |
39 | 40 |
@@ -282,7 +283,6 @@ | ||
282 | 283 | {\ |
283 | 284 | CstlIterInternal i;\ |
284 | 285 | register size_t j = 0;\ |
285 | - register size_t idx = 0;\ | |
286 | 286 | size_t n;\ |
287 | 287 | unsigned char *insert_flags;\ |
288 | 288 | CSTL_ASSERT(self && "Map_assoc_insert_range");\ |
@@ -295,7 +295,7 @@ | ||
295 | 295 | n++;\ |
296 | 296 | }\ |
297 | 297 | if (!n) return 1;\ |
298 | - insert_flags = (unsigned char *) malloc(((n - 1) / 8) + 1);\ | |
298 | + insert_flags = (unsigned char *) malloc(((n - 1) / CHAR_BIT) + 1);\ | |
299 | 299 | if (!insert_flags) return 0;\ |
300 | 300 | for (i = first; CSTL_CAST_VPTR(Name, i.in_vptr)->ne(i.data, last.data); \ |
301 | 301 | CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), j++) {\ |
@@ -303,22 +303,16 @@ | ||
303 | 303 | if (Name##_map_insert_ref(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->key(i.data), \ |
304 | 304 | CSTL_CAST_VPTR(Name, i.in_vptr)->val(i.data), 0, &success)) {\ |
305 | 305 | if (success) {\ |
306 | - insert_flags[idx] |= (unsigned char)(1 << (j % 8));\ | |
306 | + insert_flags[j / CHAR_BIT] |= (unsigned char)(1 << (j % CHAR_BIT));\ | |
307 | 307 | } else {\ |
308 | - insert_flags[idx] &= ~(unsigned char)(1 << (j % 8));\ | |
308 | + insert_flags[j / CHAR_BIT] &= ~(unsigned char)(1 << (j % CHAR_BIT));\ | |
309 | 309 | }\ |
310 | - if ((j % 8) == 7) {\ | |
311 | - idx++;\ | |
312 | - }\ | |
313 | 310 | } else {\ |
314 | 311 | register size_t k;\ |
315 | - for (i = first, k = 0, idx = 0; k < j; CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), k++) {\ | |
316 | - if (insert_flags[idx] & (unsigned char)(1 << (k % 8))) {\ | |
312 | + for (i = first, k = 0; k < j; CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), k++) {\ | |
313 | + if (insert_flags[k / CHAR_BIT] & (unsigned char)(1 << (k % CHAR_BIT))) {\ | |
317 | 314 | Name##_erase_key(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->key(i.data));\ |
318 | 315 | }\ |
319 | - if ((k % 8) == 7) {\ | |
320 | - idx++;\ | |
321 | - }\ | |
322 | 316 | }\ |
323 | 317 | free(insert_flags);\ |
324 | 318 | return 0;\ |