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

Use @scanner << readline instead of @scanner.string = @scanner.rest + readline #107

Merged
merged 1 commit into from
Jan 21, 2024
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
4 changes: 2 additions & 2 deletions benchmark/parse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contexts:
prelude: require 'rexml'
- name: master
gems:
strscan: 3.0.8
strscan: 3.0.9
prelude: |
$LOAD_PATH.unshift(File.expand_path("lib"))
require 'rexml'
Expand All @@ -19,7 +19,7 @@ contexts:
RubyVM::YJIT.enable
- name: master(YJIT)
gems:
strscan: 3.0.8
strscan: 3.0.9
prelude: |
$LOAD_PATH.unshift(File.expand_path("lib"))
require 'rexml'
Expand Down
6 changes: 1 addition & 5 deletions lib/rexml/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ def initialize(arg, block_size=500, encoding=nil)

def read
begin
# NOTE: `@scanner << readline` does not free memory, so when parsing huge XML in JRuby's DOM,
# out-of-memory error `Java::JavaLang::OutOfMemoryError: Java heap space` occurs.
# `@scanner.string = @scanner.rest + readline` frees memory that is already consumed
# and avoids this problem.
@scanner.string = @scanner.rest + readline
@scanner << readline
rescue Exception, NameError
@source = nil
end
Expand Down
2 changes: 1 addition & 1 deletion rexml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.5.0'

spec.add_runtime_dependency("strscan", ">= 3.0.8")
spec.add_runtime_dependency("strscan", ">= 3.0.9")

spec.add_development_dependency "benchmark_driver"
spec.add_development_dependency "bundler"
Expand Down