[Groonga-commit] groonga/groonga at e8a8025 [master] vector_slice: simplify

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 18 23:53:02 JST 2016


Kouhei Sutou	2016-07-18 23:53:02 +0900 (Mon, 18 Jul 2016)

  New Revision: e8a80250fad843caf7b0ee1f2181636e491019ff
  https://github.com/groonga/groonga/commit/e8a80250fad843caf7b0ee1f2181636e491019ff

  Message:
    vector_slice: simplify

  Modified files:
    plugins/functions/vector.c

  Modified: plugins/functions/vector.c (+13 -13)
===================================================================
--- plugins/functions/vector.c    2016-07-18 22:57:09 +0900 (1b39f6e)
+++ plugins/functions/vector.c    2016-07-18 23:53:02 +0900 (05f0d52)
@@ -212,24 +212,25 @@ func_vector_slice(grn_ctx *ctx, int n_args, grn_obj **args,
     slice->header.flags |= GRN_OBJ_WITH_WEIGHT;
   }
 
-  if (size == 0) {
-    return slice;
+  if (length < 0) {
+    length = size + length + 1;
   }
 
-  if (length == 0) {
-    return slice;
-  } else if (length < 0) {
+  if (length > size) {
     length = size;
   }
 
-  if (from < 0) {
-    from = size + from;
+  if (length <= 0) {
+    return slice;
+  }
+
+  while (from < 0) {
+    from += size;
   }
 
-  if (from + length > size) {
+  to = from + length;
+  if (to > size) {
     to = size;
-  } else {
-    to = from + length;
   }
 
   switch (target->header.type) {
@@ -241,9 +242,8 @@ func_vector_slice(grn_ctx *ctx, int n_args, grn_obj **args,
         unsigned int content_length;
         unsigned int weight;
         grn_id domain;
-        content_length =
-          grn_vector_get_element(ctx, target, i,
-                                 &content, &weight, &domain);
+        content_length = grn_vector_get_element(ctx, target, i,
+                                                &content, &weight, &domain);
         grn_vector_add_element(ctx, slice,
                                content, content_length, weight, domain);
       }
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index