Goktug Gokdogan has posted comments on this change.
Change subject: add StringBuffer/Builder.reverse
......................................................................
Patch Set 1:
(5 comments)
....................................................
File user/src/com/google/gwt/core/client/impl/StringBufferImpl.java
Line 48: hasSurrogatePairs |=
this doesn't mean they are a pair right? variable name is kind of
misleading.
Line 64: buffer[i] = c;
Can we simplify all these swaps in the loops with a swap(buffer, index1,
index2) method?
It should be optimized away with compiler.
Line 70: }
Actually, this implementation is optimized for in place replacement but you
are not doing a in-place replacement so you can simplify two passes into a
simpler single pass:
if(lenth <= 1)
return s;
char[] buffer = new char[length];
buffer[0] = s[length-1];
for(int i = 1; i < length; i++) {
buffer[i] = s[length-i-1];
if(Character.isSurrogatePair(buffer[i-1],buffer[i])) {
swap(buffer, i-1, i);
}
}
(I might be missing some corner cases, but you get the idea)
....................................................
File user/src/com/google/gwt/core/client/impl/StringBufferImplAppend.java
Line 24:
nit: pls remove extra spaces in the patch.
....................................................
File user/test/com/google/gwt/emultest/java/lang/StringBufferTest.java
Line 276: assertEquals("\uD801\uDC00abce", new
StringBuffer("ecba\uD801\uDC00").reverse().toString());
some other possible tests (please try to extend with other corner cases):
{
assertEqualsReverse("", "");
assertEqualsReverse(" ", " ");
assertEqualsReverse("\uD801", "\uD801");
assertEqualsReverse("\uDC00", "\uDC00");
assertEqualsReverse("\uD801\uDC00", "\uD801\uDC00");
assertEqualsReverse("\uDC00\uD801", "\uD801\uDC00");
String expected = "abcde";
assertEquals(expected, new
StringBuffer(expected).reverse().reverse().toString());
}
private static void assertEqualsReverse(String expected, String input) {
assertEquals(expected, new StringBuffer(input).reverse().toString());
}
--
To view, visit https://gwt-review.googlesource.com/2431
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I342e7ed86c0e4efa90d09bdfe0d72c79db2654c5
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Daniel Kurka <[email protected]>
Gerrit-Reviewer: Goktug Gokdogan <[email protected]>
Gerrit-HasComments: Yes
--
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "Google Web Toolkit Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.