Skip to content

Commit

Permalink
Avoid double exists() call for common resource resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jan 22, 2024
1 parent 70d9f7c commit 6bd7f02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -25,7 +25,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -431,7 +430,7 @@ protected PropertiesHolder refreshProperties(String filename, @Nullable Properti
long refreshTimestamp = (getCacheMillis() < 0 ? -1 : System.currentTimeMillis());

Resource resource = resolveResource(filename);
if (resource.exists()) {
if (resource != null) {
long fileTimestamp = -1;
if (getCacheMillis() >= 0) {
// Last-modified timestamp of file will just be read if caching with timeout.
Expand Down Expand Up @@ -508,18 +507,18 @@ protected PropertiesHolder refreshProperties(String filename, @Nullable Properti
* {@link PropertiesPersister#load(Properties, InputStream) load} methods
* for other types of resources.
* @param filename the bundle filename (basename + Locale)
* @return the {@code Resource} to use
* @return the {@code Resource} to use, or {@code null} if none found
* @since 6.1
*/
@Nullable
protected Resource resolveResource(String filename) {
Resource resource = null;
for (String fileExtension : this.fileExtensions) {
resource = this.resourceLoader.getResource(filename + fileExtension);
Resource resource = this.resourceLoader.getResource(filename + fileExtension);
if (resource.exists()) {
return resource;
}
}
return Objects.requireNonNull(resource);
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ protected void doTestMessageAccess(
if (alwaysUseMessageFormat) {
pvs.add("alwaysUseMessageFormat", Boolean.TRUE);
}
Class<?> clazz = reloadable ?
(Class<?>) ReloadableResourceBundleMessageSource.class : ResourceBundleMessageSource.class;
Class<?> clazz = reloadable ? ReloadableResourceBundleMessageSource.class : ResourceBundleMessageSource.class;
ac.registerSingleton("messageSource", clazz, pvs);
ac.refresh();

Expand Down

0 comments on commit 6bd7f02

Please sign in to comment.