Skip to content

Commit

Permalink
Fixed bug relocating nodes in the node cache after change in buffer l…
Browse files Browse the repository at this point in the history
…ength.

As I relocated each memoized result, I deleted its former location. But if another memoized result for the same rule had already been moved into that location, then I deleted the wrong result. I was moving the result I deleted to the new location, so if it wasn't the result that belonged to the memoization this screwed things up even further. Now I check if the result belonging to the memoization is stored at the previous location (that it hasn't been overwritten by another result) and only delete it if it still exists. Then I move the result pointed to by the Memoization to the correct location. Also fixed Range#transpose for end-excluding ranges.
  • Loading branch information
Nathan Sobo committed Mar 11, 2008
1 parent 42e36eb commit 8979981
Show file tree
Hide file tree
Showing 9 changed files with 1,711 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/treetop/ruby_extensions/range.rb
Expand Up @@ -9,6 +9,10 @@ def intersects?(other_range)
end

def transpose(delta)
(first + delta)..(last + delta)
if exclude_end?
(first + delta)...(last + delta)
else
(first + delta)..(last + delta)
end
end
end
5 changes: 4 additions & 1 deletion lib/treetop/runtime/memoization.rb
Expand Up @@ -20,7 +20,10 @@ def rule_index
end

def relocate(length_change)
rule_index[interval.first + length_change] = rule_index.delete(interval.first)
if rule_index[interval.first] == result
rule_index.delete(interval.first)
end
rule_index[interval.first + length_change] = result
end

def expire
Expand Down

0 comments on commit 8979981

Please sign in to comment.