Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Created March 20, 2014 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckremes/9674596 to your computer and use it in GitHub Desktop.
Save chuckremes/9674596 to your computer and use it in GitHub Desktop.
# before
def reset!
@start = @used = 0
@eof = false
@write_synced = true
end
def discard(skip)
while @start < @used
break unless @storage[@start] == skip
@start += 1
end
end
# after some "fp" is added
class IOVars
def initialize(start = 0, used = 0, eof = false, write_synced = true, *args)
@start = start
@used = used
@eof = eof
@write_synced = write_synced
# other ivars initialized here...
end
def reset!
new
end
def advance_start(count)
new(@start + count, @used, @write_synced)
end
end
def discard(skip)
while @ivars.remaining_bytes?
break unless @storage[@ivars.start] == skip
@ivars = @iovars.advance_start(1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment