You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/17 07:06:52 UTC

[camel] branch main updated: (chores) camel-util: more aggressive micro-optimizations to StringHelper#capitalize (#11127)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 31e70ff87ba (chores) camel-util: more aggressive micro-optimizations to StringHelper#capitalize (#11127)
31e70ff87ba is described below

commit 31e70ff87bab08ef55262bfe5b889efd27265395
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Thu Aug 17 09:06:45 2023 +0200

    (chores) camel-util: more aggressive micro-optimizations to StringHelper#capitalize (#11127)
---
 .../main/java/org/apache/camel/util/StringHelper.java   | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index 7430742ec61..7c8e7e053b7 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -497,15 +497,14 @@ public final class StringHelper {
         }
 
         int length = ret.length();
-        if (length == 0) {
-            return ret;
-        }
-
-        String answer = ret.substring(0, 1).toUpperCase(Locale.ENGLISH);
-        if (length > 1) {
-            answer += ret.substring(1, length);
-        }
-        return answer;
+        final char[] chars = new char[length];
+        ret.getChars(0, length, chars, 0);
+
+        // We are OK with the limitations of Character.toUpperCase. The symbols and ideographs
+        // for which it does not return the capitalized value should not be used here (this is
+        // mostly used to capitalize setters/getters)
+        chars[0] = Character.toUpperCase(chars[0]);
+        return new String(chars);
     }
 
     /**