Skip to content

Commit 7a43c4b

Browse files
committed
Improving speed and removing using Stream API.
1 parent 8c7a25e commit 7a43c4b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_string.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ def test_title_uni(self):
707707
self.assertEqual('X\U00010427x\U0001044F X\U00010427x\U0001044F'.title(),
708708
'X\U0001044Fx\U0001044F X\U0001044Fx\U0001044F')
709709
self.assertEqual('fiNNISH'.title(), 'Finnish')
710+
self.assertEqual('bfiNNISH'.title(), 'Bfinnish')
711+
self.assertEqual('fifiNNfiISH'.title(), 'Fifinnfiish')
710712
self.assertEqual('A\u03a3A'.title(), 'A\u03c3a')
711713

712714
def test_same_id():

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,13 +1547,12 @@ abstract static class TitleNode extends PythonUnaryBuiltinNode {
15471547
@Specialization
15481548
@TruffleBoundary
15491549
public String doTitle(String self) {
1550-
int[] codePoints = self.codePoints().toArray();
1551-
int len = codePoints.length;
1550+
int len = self.length();
15521551
boolean shouldBeLowerCase = false;
15531552
boolean translated;
15541553
StringBuilder converted = new StringBuilder();
1555-
for (int i = 0; i < len; i++) {
1556-
int ch = codePoints[i];
1554+
for (int offset = 0; offset < self.length();) {
1555+
int ch = self.codePointAt(offset);
15571556
translated = false;
15581557
if (Character.isAlphabetic(ch)) {
15591558
if (shouldBeLowerCase) {
@@ -1599,6 +1598,7 @@ public String doTitle(String self) {
15991598
converted.append(Character.toChars(ch));
16001599
}
16011600
}
1601+
offset += Character.charCount(ch);
16021602
}
16031603
return converted.toString();
16041604
}

0 commit comments

Comments
 (0)