[Groonga-commit] groonga/groonga [master] Use grn_hash_entry in grn_hash_get_key_value().

Back to archive index

null+****@clear***** null+****@clear*****
2012年 4月 4日 (水) 15:37:55 JST


Susumu Yata	2012-04-04 15:37:55 +0900 (Wed, 04 Apr 2012)

  New Revision: 2c6d7cb2358c5ce95013109ac07033707d518908

  Log:
    Use grn_hash_entry in grn_hash_get_key_value().

  Modified files:
    lib/hash.c

  Modified: lib/hash.c (+22 -9)
===================================================================
--- lib/hash.c    2012-04-04 15:31:48 +0900 (7d10d22)
+++ lib/hash.c    2012-04-04 15:37:55 +0900 (7c1ede3)
@@ -1976,16 +1976,29 @@ int
 grn_hash_get_key_value(grn_ctx *ctx, grn_hash *hash, grn_id id,
                        void *keybuf, int bufsize, void *valuebuf)
 {
-  void *v;
+  void *value;
   int key_size;
-  entry_str *ee;
-  if (!grn_hash_bitmap_at(ctx, hash, id)) { return 0; }
-  ee = grn_hash_entry_at(ctx, hash, id, 0);
-  if (!ee) { return 0; }
-  key_size = (hash->obj.header.flags & GRN_OBJ_KEY_VAR_SIZE) ? ee->size : hash->key_size;
-  if (bufsize >= key_size) { memcpy(keybuf, get_key(ctx, hash, ee), key_size); }
-  if (valuebuf && (v = get_value(hash, ee))) {
-    memcpy(valuebuf, v, hash->value_size);
+  grn_hash_entry *entry;
+  if (!grn_hash_bitmap_at(ctx, hash, id)) {
+    return 0;
+  }
+  entry = grn_hash_entry_at(ctx, hash, id, 0);
+  if (!entry) {
+    return 0;
+  }
+  if (hash->obj.header.flags & GRN_OBJ_KEY_VAR_SIZE) {
+    key_size = entry->header.key_size;
+  } else {
+    key_size = hash->key_size;
+  }
+  if (bufsize >= key_size) {
+    memcpy(keybuf, grn_hash_entry_get_key(ctx, hash, entry), key_size);
+  }
+  if (valuebuf) {
+    value = grn_hash_entry_get_value(hash, entry);
+    if (value) {
+      memcpy(valuebuf, value, hash->value_size);
+    }
   }
   return key_size;
 }




Groonga-commit メーリングリストの案内
Back to archive index