-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
perf: String#getBytes(Charset) vs getBytes(String) #18
Conversation
Please sign this Google Individual Contributor License Agreement: and let me know when you are done. It's required for us to use your code. |
*/ | ||
public abstract String toString(String charsetName) |
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 is a public method. Removing it will break existing clients. Please keep the old one and add a new method instead.
Filled out the CLA as requested. Will look into re-adding the method w/ the original signature shortly. |
Do you think the original method should be marked @deprecated ? |
No. The original method is used widely in our internal code base. Unless we are willing to do a global clean-up and replace all call-sites (which will take weeks or months and isn't worthwhile in this case), we shouldn't mark the old method as deprecated. |
@@ -36,6 +36,8 @@ | |||
import java.io.OutputStream; | |||
import java.io.UnsupportedEncodingException; | |||
import java.nio.ByteBuffer; | |||
import java.nio.charset.Charset; | |||
import java.nio.charset.StandardCharsets; |
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.
Please remove use of this StandardCharsets.
This StandardCharsets is introduced only since jdk 1.7. Our library supports back to jdk 1.5. We probably can drop 1.5 support soon but I believe jdk 1.6 will be supported for quite some time.
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 use of StandardCharsets. Since String#getBytes(Charset) was introduced in jdk 1.6 (which is the whole point of this change), support for jdk 1.5 cannot be provided.
ByteString chopped = unicode.substring(2, unicode.size() - 6); | ||
assertEquals(classUnderTest + ".substring() must have the expected type", | ||
classUnderTest, getActualClassName(chopped)); | ||
|
||
String roundTripString = chopped.toString(UTF_8); | ||
String roundTripString = chopped.toString(ByteString.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.
Please test both ByteString.toString(String) and ByteString.toString(Charset) here (you added a test case for the latter but removed the test case for the former).
Sync from Google-internal development.
…in-oneof Fix scalar types in oneof for proto3
Use the cleaner and slightly faster getBytes on Strings.