[Groonga-commit] groonga/groonga at 5076e4c [master] Simplify

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Tue Feb 27 10:12:32 JST 2018


Kouhei Sutou	2018-02-27 10:12:32 +0900 (Tue, 27 Feb 2018)

  New Revision: 5076e4cd61df1e15e4f5056124544bf6b80db448
  https://github.com/groonga/groonga/commit/5076e4cd61df1e15e4f5056124544bf6b80db448

  Message:
    Simplify

  Modified files:
    lib/db.c

  Modified: lib/db.c (+24 -43)
===================================================================
--- lib/db.c    2018-02-27 01:47:39 +0900 (e4850950a)
+++ lib/db.c    2018-02-27 10:12:32 +0900 (d250e4a4d)
@@ -4735,8 +4735,31 @@ grn_obj_column_(grn_ctx *ctx, grn_obj *table, const char *name, unsigned int nam
     if (len) {
       buf[len++] = GRN_DB_DELIMITER;
       if (len + name_size <= GRN_TABLE_MAX_KEY_SIZE) {
+        grn_obj alias_name_buffer;
         grn_memcpy(buf + len, name, name_size);
-        column = grn_ctx_get(ctx, buf, len + name_size);
+        GRN_TEXT_INIT(&alias_name_buffer, 0);
+        column = grn_alias_resolve(ctx,
+                                   buf,
+                                   len + name_size,
+                                   &alias_name_buffer,
+                                   GRN_TRUE);
+        if (!column && GRN_TEXT_LEN(&alias_name_buffer) > 0) {
+          const size_t delimiter_len = 1;
+          const size_t table_name_len = len - delimiter_len;
+          const char *alias_name = GRN_TEXT_VALUE(&alias_name_buffer);
+          size_t alias_name_size = GRN_TEXT_LEN(&alias_name_buffer);
+          if (alias_name_size > len &&
+              alias_name[table_name_len] == GRN_DB_DELIMITER &&
+              strncmp(alias_name, buf, table_name_len) == 0) {
+            alias_name += len;
+            alias_name_size -= len;
+          }
+          column = grn_obj_get_accessor(ctx,
+                                        table,
+                                        alias_name,
+                                        alias_name_size);
+        }
+        GRN_OBJ_FIN(ctx, &alias_name_buffer);
       } else {
         ERR(GRN_INVALID_ARGUMENT, "name is too long");
       }
@@ -4754,48 +4777,6 @@ grn_obj_column(grn_ctx *ctx, grn_obj *table, const char *name, unsigned int name
   if (GRN_OBJ_TABLEP(table)) {
     if (grn_db_check_name(ctx, name, name_size) == GRN_SUCCESS) {
       column = grn_obj_column_(ctx, table, name, name_size);
-      if (!column &&
-          !(DB_OBJ(table)->id & GRN_OBJ_TMP_OBJECT) &&
-          ctx->impl &&
-          ctx->impl->db) {
-        char column_name[GRN_TABLE_MAX_KEY_SIZE];
-        int table_name_size;
-        table_name_size = grn_obj_name(ctx,
-                                       table,
-                                       column_name,
-                                       GRN_TABLE_MAX_KEY_SIZE);
-        if (table_name_size > 0) {
-          int column_name_size = table_name_size;
-          grn_obj alias_name_buffer;
-          column_name[column_name_size++] = GRN_DB_DELIMITER;
-          grn_memcpy(column_name + column_name_size,
-                     name,
-                     name_size);
-          column_name_size += name_size;
-          GRN_TEXT_INIT(&alias_name_buffer, 0);
-          grn_alias_resolve(ctx,
-                            column_name,
-                            column_name_size,
-                            &alias_name_buffer,
-                            GRN_FALSE);
-          if (GRN_TEXT_LEN(&alias_name_buffer) > 0) {
-            const char *alias_name = GRN_TEXT_VALUE(&alias_name_buffer);
-            size_t alias_name_size = GRN_TEXT_LEN(&alias_name_buffer);
-            const size_t delimiter_size = 1;
-            if (alias_name_size > table_name_size + delimiter_size &&
-                alias_name[table_name_size] == GRN_DB_DELIMITER &&
-                strncmp(alias_name, column_name, table_name_size) == 0) {
-              alias_name += table_name_size + 1;
-              alias_name_size -= table_name_size + 1;
-            }
-            column = grn_obj_get_accessor(ctx,
-                                          table,
-                                          alias_name,
-                                          alias_name_size);
-          }
-          GRN_OBJ_FIN(ctx, &alias_name_buffer);
-        }
-      }
     }
     if (!column) {
       column = grn_obj_get_accessor(ctx, table, name, name_size);
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180227/508f7d4b/attachment-0001.htm 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る