Skip to content

Commit 1d4c42b

Browse files
authored
avoid unnecessary delete_prefix calls in line parsing (#33)
* avoid unnecessary delete_prefix calls in line parsing * change range syntax for Ruby 2.5 compatibility
1 parent f82c135 commit 1d4c42b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/ld-eventsource/impl/event_parser.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ def items
3737
event = maybe_create_event
3838
reset_buffers
3939
gen.yield event if !event.nil?
40-
elsif (colon = line.index(':'))
41-
name = line.slice(0...colon)
40+
elsif (pos = line.index(':'))
41+
name = line.slice(0...pos)
4242

43-
# delete the colon followed by an optional space
44-
line = line.slice(colon...).delete_prefix(':').delete_prefix(" ")
43+
pos += 1 # skip colon
44+
pos += 1 if pos < line.length && line[pos] == ' ' # skip optional single space, per SSE spec
45+
line = line.slice(pos..-1)
4546

4647
item = process_field(name, line)
4748
gen.yield item if !item.nil?

0 commit comments

Comments
 (0)