[Groonga-commit] groonga/groonga-command-parser at 954f9bd [master] parser: add :need_original_source option

Back to archive index
Kouhei Sutou null+****@clear*****
Wed Mar 6 10:57:31 JST 2019


Kouhei Sutou	2019-03-06 10:57:31 +0900 (Wed, 06 Mar 2019)

  Revision: 954f9bda40f970e0880665f200e4c3ab1713b447
  https://github.com/groonga/groonga-command-parser/commit/954f9bda40f970e0880665f200e4c3ab1713b447

  Message:
    parser: add :need_original_source option
    
    It's useful to reduce memory usage to parse large load.

  Modified files:
    lib/groonga/command/parser.rb
    lib/groonga/command/parser/command/groonga-command-filter.rb

  Modified: lib/groonga/command/parser.rb (+12 -7)
===================================================================
--- lib/groonga/command/parser.rb    2019-03-06 10:39:28 +0900 (776f4d7)
+++ lib/groonga/command/parser.rb    2019-03-06 10:57:31 +0900 (3ca7975)
@@ -117,7 +117,8 @@ module Groonga
         end
       end
 
-      def initialize
+      def initialize(options={})
+        @need_original_source = options.fetch(:need_original_source, true)
         reset
         initialize_hooks
       end
@@ -134,9 +135,13 @@ module Groonga
       # command, this method raises {Parser::Error}.
       def finish
         if @loading
-          raise Error.new("not completed",
-                          @command.original_source.lines.to_a.last,
-                          "")
+          original_source =****@comma*****_source
+          if original_source
+            last_line = original_source.lines.to_a.last
+          else
+            last_line = ""
+          end
+          raise Error.new("not completed", last_line, "")
         else
           catch do |tag|
             parse_line(@buffer)
@@ -245,7 +250,7 @@ module Groonga
           @command = parse_command(line)
           return if****@comma*****?
 
-          @command.original_source = line
+          @command.original_source = line if @need_original_source
           process_command
         end
       end
@@ -265,7 +270,7 @@ module Groonga
               on_load_complete(@command)
               reset
             else
-              @command.original_source << "\n"
+              @command.original_source << "\n" if @need_original_source
               @loading = true
               initialize_load_values_parser
             end
@@ -364,7 +369,7 @@ module Groonga
         end
         @load_values_parser.on_consumed = lambda do |consumed|
           if @loading
-            @command.original_source << consumed
+            @command.original_source << consumed if @Need_original_source
             if****@buffe***** == consumed.bytesize
               @buffer = "".force_encoding("ASCII-8BIT")
             else

  Modified: lib/groonga/command/parser/command/groonga-command-filter.rb (+1 -1)
===================================================================
--- lib/groonga/command/parser/command/groonga-command-filter.rb    2019-03-06 10:39:28 +0900 (7806aa0)
+++ lib/groonga/command/parser/command/groonga-command-filter.rb    2019-03-06 10:57:31 +0900 (6ff2a73)
@@ -80,7 +80,7 @@ module Groonga
           end
 
           def filter(input)
-            parser = Parser.new
+            parser = Parser.new(need_original_source: true)
             parser.on_command do |command|
               filter_command(command)
             end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190306/c05b532d/attachment-0001.html>


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