Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster #charpos #617

Merged
merged 4 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target :lib do
ignore "lib/rbs/prototype", "lib/rbs/test", "lib/rbs/test.rb"

library "set", "pathname", "json", "logger", "monitor", "tsort"
signature "stdlib/strscan/0/"
end

# target :lib do
Expand Down
2 changes: 1 addition & 1 deletion bin/rbs-prof
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ require "stackprof"

out = ENV["RBS_STACKPROF_OUT"] || 'tmp/stackprof-cpu-rbs.dump'

StackProf.run(mode: :cpu, out: out) do
StackProf.run(mode: :cpu, out: out, raw: true) do
load File.join(__dir__, "../exe/rbs")
end
2 changes: 2 additions & 0 deletions lib/rbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
require "ripper"
require "logger"
require "tsort"
require "strscan"

require "rbs/char_scanner"
require "rbs/errors"
require "rbs/buffer"
require "rbs/location"
Expand Down
20 changes: 20 additions & 0 deletions lib/rbs/char_scanner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module RBS
class CharScanner < StringScanner
def initialize(string)
super(string)
@charpos = 0
end

alias original_charpos charpos

def charpos
@charpos
end

def scan(pattern)
s = super
@charpos += s.size if s
s
end
end
end
10 changes: 2 additions & 8 deletions lib/rbs/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions lib/rbs/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,6 @@ class LocatedValue
end
end

require "strscan"

attr_reader :input
attr_reader :buffer
attr_reader :eof_re
Expand All @@ -1098,7 +1096,7 @@ def initialize(type, buffer:, eof_re:)
super()
@type = type
@buffer = buffer
@input = StringScanner.new(buffer.content)
@input = CharScanner.new(buffer.content)
@eof_re = eof_re
@eof = false
@bound_variables_stack = []
Expand Down Expand Up @@ -1214,11 +1212,7 @@ def new_token(type, value = input.matched)
end

def charpos(scanner)
if @ascii_only
scanner.pos
else
scanner.charpos
end
scanner.charpos
end

def empty_params_result
Expand Down
9 changes: 9 additions & 0 deletions sig/char_scanner.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RBS
class CharScanner < StringScanner
def initialize: (String) -> void

def original_charpos: () -> Integer

@charpos: Integer
end
end
Loading