Skip to content

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

Closed
wants to merge 7 commits into from

Conversation

miry
Copy link

@miry miry commented Aug 13, 2018

In ruby 3 option --enable-frozen-string-literal will be enabled by
default.

@miry miry force-pushed the enable-frozen-builds branch from 903f052 to b128e0d Compare August 13, 2018 18:32
@coveralls
Copy link

coveralls commented Aug 13, 2018

Coverage Status

Coverage decreased (-4.2%) to 94.557% when pulling 18ea47a on miry:enable-frozen-builds into e89f6ac on rubyzip:master.

@@ -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)
Copy link
Contributor

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?

Copy link
Author

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.

@@ -38,7 +38,7 @@ def input_finished?

private

def internal_produce_input(buf = '')
def internal_produce_input(buf = String.new)
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same encoding issue.

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same encoding issue.

Copy link
Author

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"
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

@miry miry Aug 23, 2018

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.

https://travis-ci.org/rubyzip/rubyzip/builds/415587058

@@ -55,7 +55,7 @@ def test_open_read
f.readline.chomp)
end
assert(blockCalled)
@zip_file.dir.chdir '/'
@zip_file.dir.chdir String.new('/')
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@miry
Copy link
Author

miry commented Aug 23, 2018

@bdewater thanks for your comments. I updated PR.

@miry miry force-pushed the enable-frozen-builds branch from 2699221 to 18ea47a Compare August 23, 2018 20:35
@miry
Copy link
Author

miry commented Oct 12, 2018

closing because there were no action for last 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants