From 6b184e7ad15244eb1237e349fd442c06e42a1021 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 17 May 2013 23:34:32 +0300 Subject: [PATCH] Optimize performance of Buffer#line_begins Replace push/reverse with unshift. This is generally about 10 times faster according to my simple benchmarks. --- lib/parser/source/buffer.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/parser/source/buffer.rb b/lib/parser/source/buffer.rb index 58f332af3..372432d84 100644 --- a/lib/parser/source/buffer.rb +++ b/lib/parser/source/buffer.rb @@ -109,13 +109,11 @@ def line_begins @source.each_char do |char| if char == "\n" - @line_begins << [ @line_begins.length, index ] + @line_begins.unshift [ @line_begins.length, index ] end index += 1 end - - @line_begins = @line_begins.reverse end @line_begins