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

[ruby-2.3 Feature #11785] add `encoding:` optional argument to String.new #3535

Closed
wants to merge 3 commits into from

Conversation

@cheald
Copy link
Contributor

@cheald cheald commented Dec 12, 2015

Adds kwargs support to String#initialize such that it will accept an optional :encoding argument.

…g.new`

Adds kwargs support to String#initialize such that it will accept an optional :encoding argument.
replace19(arg0);
@JRubyMethod(name = "initialize", visibility = PRIVATE, optional = 2)
public IRubyObject initialize19(ThreadContext context, IRubyObject[] args) {
final String[] validArgs = new String[]{"encoding"};

This comment has been minimized.

@cheald

cheald Dec 12, 2015
Author Contributor

I'm not quite sure what Java will do here - since it's a final String[], will it be optimized away, or is this going to result in an allocation per invocation? Should this be moved to an array initialized outside of the method?

…ated per invocation. Slightly less typechecking; now behaves similarly to ruby-head when passed invalid types for arg0.
@kares

This comment has been minimized.

believe this was kept for compatibility - so makes no sense to refactor (assuming its not used)

This comment has been minimized.

Copy link
Owner Author

@cheald cheald replied Dec 13, 2015

I don't know if it was used or not, but it wouldn't compile without the change. :)

This comment has been minimized.

Copy link

@kares kares replied Dec 13, 2015

there are other ways to fix it than changing a public signature ... new IRubyObject[] { arg0 } bellow

@kares

This comment has been minimized.

what about having (arg0) version with a (arg0, arg1) so its mostly one method call for the (arg0) case

This comment has been minimized.

Copy link
Owner Author

@cheald cheald replied Dec 13, 2015

Is the idea that we want to avoid the extra work when arg1 isn't passed? We'd still need to check if it's a hash or string; String.new(encoding: "utf-8") is valid.

This comment has been minimized.

Copy link

@kares kares replied Dec 13, 2015

aaah - in that case its probably fine as it is ... thought it always gets the first arg0 with encoding:

@kares

This comment has been minimized.

should be static

@kares
Copy link
Member

@kares kares commented Dec 13, 2015

picked onto ruby-2.3 with some tunings and maintained initialize compatibility: a3c648d ... thanks.

@kares kares closed this Dec 13, 2015
@kares kares added this to the JRuby 9.1.0.0 milestone Dec 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.