mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8288723: Avoid redundant ConcurrentHashMap.get call in java.time
Reviewed-by: attila, rriggs
This commit is contained in:
parent
3582fd9e93
commit
52cc6cd063
4 changed files with 14 additions and 28 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2022, 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
|
||||
|
@ -424,15 +424,11 @@ public final class ZoneOffset
|
|||
throw new DateTimeException("Zone offset not in valid range: -18:00 to +18:00");
|
||||
}
|
||||
if (totalSeconds % (15 * SECONDS_PER_MINUTE) == 0) {
|
||||
Integer totalSecs = totalSeconds;
|
||||
ZoneOffset result = SECONDS_CACHE.get(totalSecs);
|
||||
if (result == null) {
|
||||
result = new ZoneOffset(totalSeconds);
|
||||
SECONDS_CACHE.putIfAbsent(totalSecs, result);
|
||||
result = SECONDS_CACHE.get(totalSecs);
|
||||
return SECONDS_CACHE.computeIfAbsent(totalSeconds, totalSecs -> {
|
||||
ZoneOffset result = new ZoneOffset(totalSecs);
|
||||
ID_CACHE.putIfAbsent(result.getId(), result);
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
});
|
||||
} else {
|
||||
return new ZoneOffset(totalSeconds);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue