[Groonga-commit] groonga/groonga at 5660499 [master] mrb: use Cursor.open {|cursor| ...} style

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Feb 5 13:12:54 JST 2015


Kouhei Sutou	2015-02-05 13:12:54 +0900 (Thu, 05 Feb 2015)

  New Revision: 5660499cba9f39b76f7d9e606ea60531352d628a
  https://github.com/groonga/groonga/commit/5660499cba9f39b76f7d9e606ea60531352d628a

  Message:
    mrb: use Cursor.open {|cursor| ...} style

  Modified files:
    lib/mrb/scripts/database.rb
    plugins/sharding/search.rb

  Modified: lib/mrb/scripts/database.rb (+2 -8)
===================================================================
--- lib/mrb/scripts/database.rb    2015-02-05 13:12:24 +0900 (e69159e)
+++ lib/mrb/scripts/database.rb    2015-02-05 13:12:54 +0900 (9004e0e)
@@ -5,14 +5,11 @@ module Groonga
       flags =
         TableCursorFlags::ASCENDING |
         TableCursorFlags::BY_ID
-      cursor = TableCursor.open(self, :flags => flags)
-      begin
+      TableCursor.open(self, :flags => flags) do |cursor|
         cursor.each do |id|
           object = context[id]
           yield(object) if object
         end
-      ensure
-        cursor.close
       end
     end
 
@@ -23,14 +20,11 @@ module Groonga
         TableCursorFlags::ASCENDING |
         TableCursorFlags::BY_KEY
       flags |= TableCursorFlags::PREFIX if min
-      cursor = TableCursor.open(self, :min => min, :flags => flags)
-      begin
+      TableCursor.open(self, :min => min, :flags => flags) do |cursor|
         cursor.each do |id|
           object = context[id]
           yield(object) if object.is_a?(Table)
         end
-      ensure
-        cursor.close
       end
     end
   end

  Modified: plugins/sharding/search.rb (+5 -11)
===================================================================
--- plugins/sharding/search.rb    2015-02-05 13:12:24 +0900 (44f1a61)
+++ plugins/sharding/search.rb    2015-02-05 13:12:54 +0900 (ffd9330)
@@ -172,19 +172,13 @@ module Groonga
           flags |= TableCursorFlags::LT
         end
 
-        table_cursor = TableCursor.open(range_index.table,
-                                        :min => min,
-                                        :max => max,
-                                        :flags => flags)
-        begin
-          index_cursor = IndexCursor.open(table_cursor, range_index)
-          begin
+        TableCursor.open(range_index.table,
+                         :min => min,
+                         :max => max,
+                         :flags => flags) do |table_cursor|
+          IndexCursor.open(table_cursor, range_index) do |index_cursor|
             index_cursor.count
-          ensure
-            index_cursor.close
           end
-        ensure
-          table_cursor.close
         end
       end
 
-------------- next part --------------
HTML����������������������������...
다운로드 



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