From cee576b8b2e9a64db7f3ddcdaf16925024cfd2c3 Mon Sep 17 00:00:00 2001 From: dreis Date: Tue, 3 Jan 2017 22:37:06 +0100 Subject: [PATCH] Reduce memory footprint of AsciiBytes.hashCode Update `AsciiBytes.hashCode(int hash, String string)` so that it no longer copies the backing array of the string. Closes gh-7851 --- .../org/springframework/boot/loader/jar/AsciiBytes.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java index 62f26cedb23..333d7775f36 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -224,9 +224,8 @@ final class AsciiBytes { } public static int hashCode(int hash, String string) { - char[] chars = string.toCharArray(); - for (int i = 0; i < chars.length; i++) { - hash = 31 * hash + chars[i]; + for (int i = 0; i < string.length(); i++) { + hash = 31 * hash + string.charAt(i); } return hash; }