• R/O
  • SSH
  • HTTPS

cstl: Commit


Commit MetaInfo

Revision401 (tree)
Time2010-07-29 21:14:46
Authorkatono

Log Message

CHAR_BITを使って書き直し。

Change Summary

Incremental Difference

--- branches/try-vfunc/cstl/set.h (revision 400)
+++ branches/try-vfunc/cstl/set.h (revision 401)
@@ -34,6 +34,7 @@
3434 #define CSTL_SET_H_INCLUDED
3535
3636 #include <stdlib.h>
37+#include <limits.h>
3738 #include "common.h"
3839 #include "rbtree.h"
3940
@@ -243,7 +244,6 @@
243244 {\
244245 CstlIterInternal i;\
245246 register size_t j = 0;\
246- register size_t idx = 0;\
247247 size_t n;\
248248 unsigned char *insert_flags;\
249249 CSTL_ASSERT(self && "Set_assoc_insert_range");\
@@ -259,7 +259,7 @@
259259 }\
260260 }\
261261 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);\
263263 if (!insert_flags) return 0;\
264264 for (i = first; CSTL_CAST_VPTR(Name, i.in_vptr)->ne(i.data, last.data); \
265265 CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), j++) {\
@@ -266,22 +266,16 @@
266266 int success;\
267267 if (Name##_set_insert(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->data(i.data), 0, &success)) {\
268268 if (success) {\
269- insert_flags[idx] |= (unsigned char)(1 << (j % 8));\
269+ insert_flags[j / CHAR_BIT] |= (unsigned char)(1 << (j % CHAR_BIT));\
270270 } else {\
271- insert_flags[idx] &= ~(unsigned char)(1 << (j % 8));\
271+ insert_flags[j / CHAR_BIT] &= ~(unsigned char)(1 << (j % CHAR_BIT));\
272272 }\
273- if ((j % 8) == 7) {\
274- idx++;\
275- }\
276273 } else {\
277274 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))) {\
280277 Name##_erase_key(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->data(i.data));\
281278 }\
282- if ((k % 8) == 7) {\
283- idx++;\
284- }\
285279 }\
286280 free(insert_flags);\
287281 return 0;\
--- branches/try-vfunc/cstl/map.h (revision 400)
+++ branches/try-vfunc/cstl/map.h (revision 401)
@@ -34,6 +34,7 @@
3434 #define CSTL_MAP_H_INCLUDED
3535
3636 #include <stdlib.h>
37+#include <limits.h>
3738 #include "common.h"
3839 #include "rbtree.h"
3940
@@ -282,7 +283,6 @@
282283 {\
283284 CstlIterInternal i;\
284285 register size_t j = 0;\
285- register size_t idx = 0;\
286286 size_t n;\
287287 unsigned char *insert_flags;\
288288 CSTL_ASSERT(self && "Map_assoc_insert_range");\
@@ -295,7 +295,7 @@
295295 n++;\
296296 }\
297297 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);\
299299 if (!insert_flags) return 0;\
300300 for (i = first; CSTL_CAST_VPTR(Name, i.in_vptr)->ne(i.data, last.data); \
301301 CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), j++) {\
@@ -303,22 +303,16 @@
303303 if (Name##_map_insert_ref(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->key(i.data), \
304304 CSTL_CAST_VPTR(Name, i.in_vptr)->val(i.data), 0, &success)) {\
305305 if (success) {\
306- insert_flags[idx] |= (unsigned char)(1 << (j % 8));\
306+ insert_flags[j / CHAR_BIT] |= (unsigned char)(1 << (j % CHAR_BIT));\
307307 } else {\
308- insert_flags[idx] &= ~(unsigned char)(1 << (j % 8));\
308+ insert_flags[j / CHAR_BIT] &= ~(unsigned char)(1 << (j % CHAR_BIT));\
309309 }\
310- if ((j % 8) == 7) {\
311- idx++;\
312- }\
313310 } else {\
314311 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))) {\
317314 Name##_erase_key(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->key(i.data));\
318315 }\
319- if ((k % 8) == 7) {\
320- idx++;\
321- }\
322316 }\
323317 free(insert_flags);\
324318 return 0;\
Show on old repository browser