summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-03-16 08:19:02 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-03-16 08:19:02 -0700
commitd2c5dff657c4547ada04f939dfa341ba56f743cd (patch)
tree6a7353ed22c5f3bf16f390a48042950af57a796c
parent2e937a5bba696ce851178f89af1abe9d7f2bcbc2 (diff)
parent7de2deab1e5254a3dbf48714aca3732b64b1f2fa (diff)
downloadmruby-d2c5dff657c4547ada04f939dfa341ba56f743cd.tar.gz
mruby-d2c5dff657c4547ada04f939dfa341ba56f743cd.zip
Merge pull request #1015 from monaka/pr-khash-cleanup-20130316
khash cleanup.
-rw-r--r--include/mruby/khash.h19
-rw-r--r--src/class.c1
-rw-r--r--tasks/mrbgems_test.rake2
3 files changed, 15 insertions, 7 deletions
diff --git a/include/mruby/khash.h b/include/mruby/khash.h
index 9eddc0bb3..373e54b13 100644
--- a/include/mruby/khash.h
+++ b/include/mruby/khash.h
@@ -12,7 +12,6 @@ extern "C" {
#endif
#include <stdint.h>
-#include <string.h>
typedef uint32_t khint_t;
typedef khint_t khiter_t;
@@ -22,7 +21,7 @@ typedef khint_t khiter_t;
#endif
#define KHASH_MIN_SIZE 8
-#define UPPER_BOUND(x) ((x)>>2|(x>>1))
+#define UPPER_BOUND(x) ((x)>>2|(x)>>1)
//extern uint8_t __m[];
@@ -75,6 +74,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void kh_del_##name(kh_##name##_t *h, khint_t x); \
kh_##name##_t *kh_copy_##name(mrb_state *mrb, kh_##name##_t *h);
+static inline void
+kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
+{
+ while (len-- > 0) {
+ *p++ = c;
+ }
+}
+
/* define kh_xxx_funcs
name: hash name
@@ -92,8 +99,8 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
h->upper_bound = UPPER_BOUND(sz); \
h->e_flags = (uint8_t *)mrb_malloc(h->mrb, sizeof(uint8_t)*sz/4); \
h->d_flags = h->e_flags + sz/8; \
- memset(h->e_flags, 0xff, sz/8*sizeof(uint8_t)); \
- memset(h->d_flags, 0x00, sz/8*sizeof(uint8_t)); \
+ kh_fill_flags(h->e_flags, 0xff, sz/8); \
+ kh_fill_flags(h->d_flags, 0x00, sz/8); \
h->keys = (khkey_t *)mrb_malloc(h->mrb, sizeof(khkey_t)*sz); \
h->vals = (khval_t *)mrb_malloc(h->mrb, sizeof(khval_t)*sz); \
h->mask = sz-1; \
@@ -124,8 +131,8 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void kh_clear_##name(kh_##name##_t *h) \
{ \
if (h && h->e_flags) { \
- memset(h->e_flags, 0xff, h->n_buckets/8*sizeof(uint8_t)); \
- memset(h->d_flags, 0x00, h->n_buckets/8*sizeof(uint8_t)); \
+ kh_fill_flags(h->e_flags, 0xff, h->n_buckets/8); \
+ kh_fill_flags(h->d_flags, 0x00, h->n_buckets/8); \
h->size = h->n_occupied = 0; \
} \
} \
diff --git a/src/class.c b/src/class.c
index 59431c26e..d53629636 100644
--- a/src/class.c
+++ b/src/class.c
@@ -7,6 +7,7 @@
#include "mruby.h"
#include <stdarg.h>
#include <ctype.h>
+#include <string.h>
#include "mruby/class.h"
#include "mruby/proc.h"
#include "mruby/string.h"
diff --git a/tasks/mrbgems_test.rake b/tasks/mrbgems_test.rake
index 6ca5eaef2..e725f1c4d 100644
--- a/tasks/mrbgems_test.rake
+++ b/tasks/mrbgems_test.rake
@@ -68,7 +68,7 @@ MRuby.each_target do
f.puts %Q[ ]
f.puts %Q[ while(mrb_test(val2)) {]
f.puts %Q[ char *str = mrb_string_value_cstr(mrb2, &val2);]
- f.puts %Q[ mrb_ary_push(mrb, ary1, mrb_str_new(mrb, str, strlen(str)));]
+ f.puts %Q[ mrb_ary_push(mrb, ary1, mrb_str_new_cstr(mrb, str));]
f.puts %Q[ val2 = mrb_ary_shift(mrb2, ary2);]
f.puts %Q[ }]
f.puts %Q[ }]