Skip to content

Commit 8c41d35

Browse files
authored
Optimization of REXML::Parsers::SAX2Parser#get_procs, #get_listeners (#303)
## Benchmark ``` $ benchmark-driver benchmark/sax.yaml before after before(YJIT) after(YJIT) sax 2.309k 2.317k 2.760k 2.879k i/s - 100.000 times in 0.043300s 0.043155s 0.036238s 0.034738s Comparison: sax after(YJIT): 2878.7 i/s before(YJIT): 2759.5 i/s - 1.04x slower after: 2317.2 i/s - 1.24x slower before: 2309.5 i/s - 1.25x slower ``` - YJIT=ON : 1.04x faster - YJIT=OFF : 1.00x faster
1 parent aae683c commit 8c41d35

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/rexml/parsers/sax2parser.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,17 @@ def get_procs( symbol, name )
226226
return nil if @procs.size == 0
227227
@procs.find_all do |sym, match, block|
228228
(
229-
(sym.nil? or symbol == sym) and
230-
((name.nil? and match.nil?) or match.nil? or (
231-
(name == match) or
232-
(match.kind_of? Regexp and name =~ match)
233-
)
234-
)
229+
(sym.nil? or (symbol == sym)) and
230+
(match.nil? or (name == match) or (match.kind_of? Regexp and match.match?(name)))
235231
)
236232
end.collect{|x| x[-1]}
237233
end
238234
def get_listeners( symbol, name )
239235
return nil if @listeners.size == 0
240236
@listeners.find_all do |sym, match, block|
241237
(
242-
(sym.nil? or symbol == sym) and
243-
((name.nil? and match.nil?) or match.nil? or (
244-
(name == match) or
245-
(match.kind_of? Regexp and name =~ match)
246-
)
247-
)
238+
(sym.nil? or (symbol == sym)) and
239+
(match.nil? or (name == match) or (match.kind_of? Regexp and match.match?(name)))
248240
)
249241
end.collect{|x| x[-1]}
250242
end

0 commit comments

Comments
 (0)