-
Notifications
You must be signed in to change notification settings - Fork 315
Add test build with frozen strings #374
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
Conversation
903f052
to
b128e0d
Compare
lib/zip/inflater.rb
Outdated
@@ -12,7 +12,7 @@ def sysread(number_of_bytes = nil, buf = '') | |||
readEverything = number_of_bytes.nil? | |||
while readEverything || @output_buffer.bytesize < number_of_bytes | |||
break if internal_input_finished? | |||
@output_buffer << internal_produce_input(buf) | |||
@output_buffer += internal_produce_input(buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create a new and appended string for every loop, not very efficient. Why not change the method signature to def sysread(number_of_bytes = nil, buf = String.new(''))
for a mutable string we can append to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdewater Fixed in this method signature and other places where string initialized.
lib/zip/inflater.rb
Outdated
@@ -38,7 +38,7 @@ def input_finished? | |||
|
|||
private | |||
|
|||
def internal_produce_input(buf = '') | |||
def internal_produce_input(buf = String.new) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String.new
without an argument will default to ASCII-8BIT encoding while ''
is UTF-8. If you change this to String.new('')
the encoding will remain UTF-8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdewater good to know. fixed.
@@ -11,26 +11,27 @@ def initialize | |||
super | |||
@lineno = 0 | |||
@pos = 0 | |||
@output_buffer = '' | |||
@output_buffer = String.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same encoding issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
end | ||
|
||
attr_accessor :lineno | ||
attr_reader :pos | ||
|
||
def read(number_of_bytes = nil, buf = '') | ||
buffer = buf.dup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you make buf
a mutable String.new('')
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted.
@@ -76,7 +77,7 @@ def gets(a_sep_string = $/, number_of_bytes = nil) | |||
while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit | |||
buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max | |||
return @output_buffer.empty? ? nil : flush if input_finished? | |||
@output_buffer << produce_input | |||
@output_buffer += produce_input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same appending issue as mentioned above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdewater thanks. Fixed.
@@ -90,7 +91,7 @@ def ungetc(byte) | |||
|
|||
def flush | |||
ret_val = @output_buffer | |||
@output_buffer = '' | |||
@output_buffer = String.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same encoding issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdewater fixed
@@ -17,6 +17,9 @@ matrix: | |||
jdk: openjdk7 | |||
- rvm: jruby-head | |||
jdk: oraclejdk8 | |||
- rvm: ruby-head | |||
env: | |||
- RUBYOPT="--enable-frozen-string-literal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put the # frozen_string_literal: true
magic comment a top of every file so that every Ruby 2.3+ user can reap the benefits? I doubt a lot of people can their Ruby app with this RUBYOPT flag since not every gem is ready for this yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdewater I don't think to update all files in gem, without automatic rubocop/lint checking is useful. It would inconsistent file to file.
I wanted to check that gem is ready, even without force people who uses gem to fix code. I came to this PR exactly, because enabled in all file of a project # frozen_string_literal: true
. I don't think I fixed all problems. But at least it would be in the matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This record is optional. And it is included ruby head tests without any env.
@@ -55,7 +55,7 @@ def test_open_read | |||
f.readline.chomp) | |||
end | |||
assert(blockCalled) | |||
@zip_file.dir.chdir '/' | |||
@zip_file.dir.chdir String.new('/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@bdewater thanks for your comments. I updated PR. |
In ruby 3 option `--enable-frozen-string-literal` will be enabled by default.
2699221
to
18ea47a
Compare
closing because there were no action for last 30 days. |
In ruby 3 option
--enable-frozen-string-literal
will be enabled bydefault.