From 6e0a1efcd6c44dd835abf034476ce260d5afcb20 Mon Sep 17 00:00:00 2001 From: RalfBarkow Date: Tue, 22 Oct 2024 19:51:23 +0200 Subject: [PATCH] Refactor: Reduce redundant calls to getActivatedEntryNumber in getEntryHeading - Store the result of getActivatedEntryNumber in a local variable to avoid multiple method calls. - Simplified the conditional logic by reusing the stored variable. - Improves performance and code readability. --- .../zettelkasten/util/HtmlUbbUtil.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java b/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java index 04e39715..3da34e46 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java +++ b/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java @@ -254,15 +254,19 @@ private static String getEntryHeading(Daten dataObj, int entrynr, int sourcefram StringBuilder heading = new StringBuilder(); heading.append(resourceMap.getString("zettelDesc")).append(" "); - if (entrynr != dataObj.getActivatedEntryNumber() && sourceframe != Constants.FRAME_SEARCH) { + // Store the result of getActivatedEntryNumber to avoid multiple calls + int activatedEntryNumber = dataObj.getActivatedEntryNumber(); + Constants.zknlogger.info("Activated entry number: " + activatedEntryNumber); + + if (entrynr != activatedEntryNumber && sourceframe != Constants.FRAME_SEARCH) { heading.append("") - .append(" ").append(dataObj.getActivatedEntryNumber()).append(" » ") - .append("") - .append(entrynr).append(" (").append(wordCount).append(" ") - .append(resourceMap.getString("activatedZettelWordCount")).append(")"); + .append(" ").append(activatedEntryNumber).append(" » ") + .append("") + .append(entrynr).append(" (").append(wordCount).append(" ") + .append(resourceMap.getString("activatedZettelWordCount")).append(")"); } else { heading.append(entrynr).append(" (").append(wordCount).append(" ") - .append(resourceMap.getString("activatedZettelWordCount")).append(")"); + .append(resourceMap.getString("activatedZettelWordCount")).append(")"); } return heading.toString();