mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8221723: Avoid storing zero to String.hash
Reviewed-by: shade, prappo, jiangli
This commit is contained in:
parent
6bce53795b
commit
1908897b93
2 changed files with 20 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -42,11 +42,13 @@ public class StringHashCode {
|
|||
|
||||
private String hashcode;
|
||||
private String hashcode0;
|
||||
private String empty;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
hashcode = "abcdefghijkl";
|
||||
hashcode0 = new String(new char[]{72, 90, 100, 89, 105, 2, 72, 90, 100, 89, 105, 2});
|
||||
empty = new String();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,4 +68,13 @@ public class StringHashCode {
|
|||
public int notCached() {
|
||||
return hashcode0.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Benchmark testing String.hashCode() with the empty string. Since the
|
||||
* empty String has hashCode = 0, this value is always recalculated.
|
||||
*/
|
||||
@Benchmark
|
||||
public int empty() {
|
||||
return empty.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue