From 5321a6701c1d75b5fb944dfe9e2b83b010be289d Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:33:19 +0800 Subject: [PATCH] perf(bukkit): Early return if no files to load --- .../main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java | 3 ++- .../main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java index ff3ffbf..56bd8af 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java @@ -36,6 +36,7 @@ public List allow() { .filter(Files::isRegularFile) .map(Path::toFile) .collect(Collectors.toList()); + if (files.isEmpty()) return Collections.emptyList(); files.parallelStream() .forEach(file -> { @@ -47,7 +48,7 @@ public List allow() { LOGGER.severe("Error reading file: " + file.getName()); } }); - if (!files.isEmpty()) LOGGER.info("Loaded " + files.size() + " external allow file(s)."); + LOGGER.info("Loaded " + files.size() + " external allow file(s). " + "Total words: " + totalList.size()); } catch (IOException e) { LOGGER.severe("Error occurred while loading external allow files: " + e.getMessage()); return Collections.emptyList(); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java index 137b36d..bad0837 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java @@ -36,6 +36,7 @@ public List deny() { .filter(Files::isRegularFile) .map(Path::toFile) .collect(Collectors.toList()); + if (files.isEmpty()) return Collections.emptyList(); files.parallelStream() .forEach(file -> { @@ -47,7 +48,7 @@ public List deny() { LOGGER.severe("Error reading file: " + file.getName()); } }); - if (!files.isEmpty()) LOGGER.info("Loaded " + files.size() + " external deny file(s)."); + LOGGER.info("Loaded " + files.size() + " external deny file(s). " + "Total words: " + totalList.size()); } catch (IOException e) { LOGGER.severe("Error occurred while loading external deny files: " + e.getMessage()); return Collections.emptyList();