mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8345668: ZoneOffset.ofTotalSeconds performance regression
Reviewed-by: rriggs, aturbanov
This commit is contained in:
parent
12700cb81b
commit
9a60f4457b
3 changed files with 31 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2024, 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,11 +424,17 @@ 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) {
|
||||
return SECONDS_CACHE.computeIfAbsent(totalSeconds, totalSecs -> {
|
||||
ZoneOffset result = new ZoneOffset(totalSecs);
|
||||
Integer totalSecs = totalSeconds;
|
||||
ZoneOffset result = SECONDS_CACHE.get(totalSecs);
|
||||
if (result == null) {
|
||||
result = new ZoneOffset(totalSeconds);
|
||||
var existing = SECONDS_CACHE.putIfAbsent(totalSecs, result);
|
||||
if (existing != null) {
|
||||
result = existing;
|
||||
}
|
||||
ID_CACHE.putIfAbsent(result.getId(), result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return new ZoneOffset(totalSeconds);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, 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
|
||||
|
@ -309,7 +309,15 @@ class DateTimeTextProvider {
|
|||
|
||||
private Object findStore(TemporalField field, Locale locale) {
|
||||
Entry<TemporalField, Locale> key = createEntry(field, locale);
|
||||
return CACHE.computeIfAbsent(key, e -> createStore(e.getKey(), e.getValue()));
|
||||
Object store = CACHE.get(key);
|
||||
if (store == null) {
|
||||
store = createStore(field, locale);
|
||||
var existing = CACHE.putIfAbsent(key, store);
|
||||
if (existing != null) {
|
||||
store = existing;
|
||||
}
|
||||
}
|
||||
return store;
|
||||
}
|
||||
|
||||
private static int toWeekDay(int calWeekDay) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, 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
|
||||
|
@ -160,7 +160,15 @@ public final class DecimalStyle {
|
|||
*/
|
||||
public static DecimalStyle of(Locale locale) {
|
||||
Objects.requireNonNull(locale, "locale");
|
||||
return CACHE.computeIfAbsent(locale, DecimalStyle::create);
|
||||
DecimalStyle info = CACHE.get(locale);
|
||||
if (info == null) {
|
||||
info = create(locale);
|
||||
var existing = CACHE.putIfAbsent(locale, info);
|
||||
if (existing != null) {
|
||||
info = existing;
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
private static DecimalStyle create(Locale locale) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue