[Groonga-commit] groonga/groonga [master] Use *n_garbages to skip grn_array_bitmap_at().

Back to archive index

null+****@clear***** null+****@clear*****
2012年 4月 3日 (火) 16:20:41 JST


Susumu Yata	2012-04-03 16:20:41 +0900 (Tue, 03 Apr 2012)

  New Revision: bf8d42050420fcbbdd0bac99c04615e8048a0260

  Log:
    Use *n_garbages to skip grn_array_bitmap_at().

  Modified files:
    lib/hash.c

  Modified: lib/hash.c (+12 -2)
===================================================================
--- lib/hash.c    2012-04-03 16:17:59 +0900 (2664fd4)
+++ lib/hash.c    2012-04-03 16:20:41 +0900 (554276d)
@@ -678,8 +678,18 @@ grn_array_delete_by_id(grn_ctx *ctx, grn_array *array, grn_id id,
 grn_id
 grn_array_at(grn_ctx *ctx, grn_array *array, grn_id id)
 {
-  /* TODO: Use *n_garbages to skip grn_array_bitmap_at(). */
-  return (grn_array_bitmap_at(ctx, array, id) == 1) ? id : GRN_ID_NIL;
+  if (*array->n_garbages) {
+    /*
+     * grn_array_bitmap_at() is a time-consuming function, so it is called only
+     * when there are garbages in the array.
+     */
+    if (grn_array_bitmap_at(ctx, array, id) != 1) {
+      return GRN_ID_NIL;
+    }
+  } else if (id > grn_array_get_max_id(array)) {
+    return GRN_ID_NIL;
+  }
+  return id;
 }
 
 grn_rc




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