From 5121ca5d17f631863cd29811ab91f8f2f2fdbb79 Mon Sep 17 00:00:00 2001 From: Marten Deinum Date: Wed, 18 Nov 2020 13:40:01 +0100 Subject: [PATCH 1/2] Reduce the overhead of char[] creation See gh-24204 --- .../boot/actuate/health/SimpleHttpCodeStatusMapper.java | 3 ++- .../boot/actuate/health/SimpleStatusAggregator.java | 3 ++- .../configurationprocessor/metadata/ConfigurationMetadata.java | 3 ++- .../org/springframework/boot/env/ConfigTreePropertySource.java | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java index 934c36b6f6..c30faab573 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java @@ -81,7 +81,8 @@ public class SimpleHttpCodeStatusMapper implements HttpCodeStatusMapper { return null; } StringBuilder builder = new StringBuilder(); - for (char ch : code.toCharArray()) { + for (int i = 0; i < code.length(); i++) { + char ch = code.charAt(i); if (Character.isAlphabetic(ch) || Character.isDigit(ch)) { builder.append(Character.toLowerCase(ch)); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleStatusAggregator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleStatusAggregator.java index 42d200bcb3..4c5b9efe79 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleStatusAggregator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleStatusAggregator.java @@ -89,7 +89,8 @@ public class SimpleStatusAggregator implements StatusAggregator { return null; } StringBuilder builder = new StringBuilder(); - for (char ch : code.toCharArray()) { + for (int i = 0; i < code.length(); i++) { + char ch = code.charAt(i); if (Character.isAlphabetic(ch) || Character.isDigit(ch)) { builder.append(Character.toLowerCase(ch)); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 7d3c9ce278..1281954f59 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -189,7 +189,8 @@ public class ConfigurationMetadata { static String toDashedCase(String name) { StringBuilder dashed = new StringBuilder(); Character previous = null; - for (char current : name.toCharArray()) { + for (int i = 0; i < name.length(); i++) { + char current = name.charAt(i); if (SEPARATORS.contains(current)) { dashed.append("-"); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java index fd71316ee3..222a426461 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/ConfigTreePropertySource.java @@ -308,7 +308,8 @@ public class ConfigTreePropertySource extends EnumerablePropertySource imp return string; } int numberOfLines = 0; - for (char ch : string.toCharArray()) { + for (int i = 0; i < string.length(); i++) { + char ch = string.charAt(i); if (ch == '\n') { numberOfLines++; } From 5da27ea57a6bd99aff1cba33ffdbbd2b0a4c6f5f Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 21 Dec 2020 10:23:33 +0100 Subject: [PATCH 2/2] Polish "Reduce the overhead of char[] creation" See gh-24204 --- .../boot/actuate/health/SimpleHttpCodeStatusMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java index c30faab573..9f4f9321e6 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHttpCodeStatusMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.