Skip to content

Commit d2ef5a9

Browse files
committed
fix: route Compiler.call through DSL.parse for ISC maps
Compiler.call called parse_isc directly for .isc paths, re-running a ~30 s Parslet parse on every compiler instantiation — the spec's shared compile cache never got a hit on the first call per compiler, so the first example of every large map timed out. DSL.parse locates, dispatches and caches; one entry point, one cache.
1 parent cf38afa commit d2ef5a9

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎lib/interscript/compiler.rb‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,10 @@ class Interscript::Compiler
99
attr_accessor :code
1010

1111
def self.call(map, **kwargs)
12-
if String === map
13-
path = begin
14-
Interscript.locate(map)
15-
rescue
16-
nil
17-
end
18-
map = if path&.end_with?(".isc")
19-
parse_isc(path)
20-
else
21-
Interscript::DSL.parse(map)
22-
end
23-
end
12+
# DSL.parse locates, dispatches .isc and caches the parsed document —
13+
# calling parse_isc here re-ran a ~30 s Parslet parse on every
14+
# compiler instantiation.
15+
map = Interscript::DSL.parse(map) if String === map
2416
compiler = new
2517
compiler.compile(map, **kwargs)
2618
compiler

‎spec/maps_listing_spec.rb‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,20 @@ def with_load_path(dir)
7070
end
7171
end
7272
end
73+
74+
RSpec.describe "Compiler.call on ISC maps" do
75+
it "reuses the cached document — repeated calls must not re-run the ISC parser" do
76+
maps = File.expand_path(MAPS)
77+
skip "maps checkout not present" unless File.file?(File.expand_path("alalc-aze-Arab-Latn-1997.isc", maps))
78+
79+
added = Interscript.load_path.first != maps
80+
Interscript.load_path.unshift(maps) if added
81+
begin
82+
a = Interscript::Interpreter.call("alalc-aze-Arab-Latn-1997")
83+
b = Interscript::Interpreter.call("alalc-aze-Arab-Latn-1997")
84+
expect(a.map.equal?(b.map)).to be(true)
85+
ensure
86+
Interscript.load_path.delete_at(0) if added
87+
end
88+
end
89+
end

0 commit comments

Comments
 (0)