Skip to content

Instantly share code, notes, and snippets.

@mlschroe
Created September 2, 2011 18:29
Show Gist options
  • Select an option

  • Save mlschroe/1189409 to your computer and use it in GitHub Desktop.

Select an option

Save mlschroe/1189409 to your computer and use it in GitHub Desktop.
--- compilers/pct/src/PCT/HLLCompiler.pir.orig 2011-08-31 13:29:53.000000000 +0000
+++ compilers/pct/src/PCT/HLLCompiler.pir 2011-08-31 14:59:36.000000000 +0000
@@ -1009,8 +1009,22 @@ memoize the line offsets as a C<!lineof>
# element is the line number to be returned.
# (Potential optimization: use a binary search.)
.local int line, count
+ .local pmc lastpos, lastline
count = elements linepos
line = 0
+ unless cache goto line_loop
+ lastpos = getprop '!linepos_lastpos', target
+ lastline = getprop '!linepos_lastline', target
+ unless null lastpos goto line_loop_tstlast
+ lastpos = new ['Integer']
+ lastline = new ['Integer']
+ setprop target, '!linepos_lastpos', lastpos
+ setprop target, '!linepos_lastline', lastline
+ goto line_loop
+ line_loop_tstlast:
+ $I0 = lastpos
+ if $I0 > pos goto line_loop
+ line = lastline
line_loop:
if line >= count goto line_done
$I0 = linepos[line]
@@ -1018,6 +1032,10 @@ memoize the line offsets as a C<!lineof>
inc line
goto line_loop
line_done:
+ unless cache goto line_done2
+ lastpos = pos
+ lastline = line
+ line_done2:
.return (line)
.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment