• R/O
  • SSH
  • HTTPS

cstl: Commit


Commit MetaInfo

Revision400 (tree)
Time2010-07-27 22:23:43
Authorkatono

Log Message

一時バッファにbit単位でフラグを格納するようにして一時バッファの確保するサイズを小さくした。

Change Summary

Incremental Difference

--- branches/try-vfunc/cstl/set.h (revision 399)
+++ branches/try-vfunc/cstl/set.h (revision 400)
@@ -243,8 +243,9 @@
243243 {\
244244 CstlIterInternal i;\
245245 register size_t j = 0;\
246+ register size_t idx = 0;\
246247 size_t n;\
247- char *insert_flags;\
248+ unsigned char *insert_flags;\
248249 CSTL_ASSERT(self && "Set_assoc_insert_range");\
249250 CSTL_ASSERT(self->magic == self && "Set_assoc_insert_range");\
250251 CSTL_ASSERT(CSTL_CAST_VPTR(Name, first.in_vptr) == CSTL_CAST_VPTR(Name, last.in_vptr) && "Set_assoc_insert_range");\
@@ -257,19 +258,30 @@
257258 n++;\
258259 }\
259260 }\
260- insert_flags = (char *) malloc(n * sizeof(char));\
261+ if (!n) return 1;\
262+ insert_flags = (unsigned char *) malloc(((n - 1) / 8) + 1);\
261263 if (!insert_flags) return 0;\
262264 for (i = first; CSTL_CAST_VPTR(Name, i.in_vptr)->ne(i.data, last.data); \
263265 CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), j++) {\
264266 int success;\
265267 if (Name##_set_insert(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->data(i.data), 0, &success)) {\
266- insert_flags[j] = (success != 0);\
268+ if (success) {\
269+ insert_flags[idx] |= (unsigned char)(1 << (j % 8));\
270+ } else {\
271+ insert_flags[idx] &= ~(unsigned char)(1 << (j % 8));\
272+ }\
273+ if ((j % 8) == 7) {\
274+ idx++;\
275+ }\
267276 } else {\
268277 register size_t k;\
269- for (i = first, k = 0; k < j; CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), k++) {\
270- if (insert_flags[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))) {\
271280 Name##_erase_key(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->data(i.data));\
272281 }\
282+ if ((k % 8) == 7) {\
283+ idx++;\
284+ }\
273285 }\
274286 free(insert_flags);\
275287 return 0;\
--- branches/try-vfunc/cstl/map.h (revision 399)
+++ branches/try-vfunc/cstl/map.h (revision 400)
@@ -282,8 +282,9 @@
282282 {\
283283 CstlIterInternal i;\
284284 register size_t j = 0;\
285+ register size_t idx = 0;\
285286 size_t n;\
286- char *insert_flags;\
287+ unsigned char *insert_flags;\
287288 CSTL_ASSERT(self && "Map_assoc_insert_range");\
288289 CSTL_ASSERT(self->magic == self && "Map_assoc_insert_range");\
289290 CSTL_ASSERT(CSTL_CAST_VPTR(Name, first.in_vptr) == CSTL_CAST_VPTR(Name, last.in_vptr) && "Map_assoc_insert_range");\
@@ -293,7 +294,8 @@
293294 CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data)) {\
294295 n++;\
295296 }\
296- insert_flags = (char *) malloc(n * sizeof(char));\
297+ if (!n) return 1;\
298+ insert_flags = (unsigned char *) malloc(((n - 1) / 8) + 1);\
297299 if (!insert_flags) return 0;\
298300 for (i = first; CSTL_CAST_VPTR(Name, i.in_vptr)->ne(i.data, last.data); \
299301 CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), j++) {\
@@ -300,13 +302,23 @@
300302 int success;\
301303 if (Name##_map_insert_ref(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->key(i.data), \
302304 CSTL_CAST_VPTR(Name, i.in_vptr)->val(i.data), 0, &success)) {\
303- insert_flags[j] = (success != 0);\
305+ if (success) {\
306+ insert_flags[idx] |= (unsigned char)(1 << (j % 8));\
307+ } else {\
308+ insert_flags[idx] &= ~(unsigned char)(1 << (j % 8));\
309+ }\
310+ if ((j % 8) == 7) {\
311+ idx++;\
312+ }\
304313 } else {\
305314 register size_t k;\
306- for (i = first, k = 0; k < j; CSTL_CAST_VPTR(Name, i.in_vptr)->inc(&i.data), k++) {\
307- if (insert_flags[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))) {\
308317 Name##_erase_key(self, *CSTL_CAST_VPTR(Name, i.in_vptr)->key(i.data));\
309318 }\
319+ if ((k % 8) == 7) {\
320+ idx++;\
321+ }\
310322 }\
311323 free(insert_flags);\
312324 return 0;\
--- branches/try-vfunc/cstl/common.h (revision 399)
+++ branches/try-vfunc/cstl/common.h (revision 400)
@@ -53,7 +53,7 @@
5353 #define CSTL_MAGIC(x)
5454 #define CSTL_ASSERT(x) ((void) 0)
5555 #endif
56-#define CSTL_ASSERT_SELF(s) (CSTL_ASSERT(s), CSTL_ASSERT((s)->magic == (s)))
56+#define CSTL_ASSERT_SELF(s) CSTL_ASSERT(s), CSTL_ASSERT((s)->magic == (s))
5757
5858 #define CSTL_UNUSED_PARAM(x) (void) x
5959
Show on old repository browser