From d988f91aba1ff2325073a8033c259aaa1fcb355b Mon Sep 17 00:00:00 2001 From: Dmitry Cherniachenko <2sabio@gmail.com> Date: Tue, 30 Jan 2024 00:15:56 +0100 Subject: [PATCH] Use orElseGet() to avoid unnecessary object allocation (#13048) --- lucene/CHANGES.txt | 3 +++ .../app/desktop/components/SearchPanelProvider.java | 10 +++++----- .../dialog/documents/AddDocumentDialogFactory.java | 2 +- .../lucene/luke/models/analysis/AnalysisImpl.java | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 7a6d4212245..f0a5dea07a8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -259,6 +259,9 @@ Other * GITHUB#12934: Cleaning up old references to Lucene/Solr. (Jakub Slowinski) +* GITHUB#12967, GITHUB#13038, GITHUB#13040, GITHUB#13042, GITHUB#13047, GITHUB#13048, GITHUB#13049, GITHUB#13050, GITHUB#13051: + Code cleanups and optimizations. (Dmitry Cherniachenko) + ======================== Lucene 9.9.2 ======================= Bug Fixes diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/SearchPanelProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/SearchPanelProvider.java index b0015456fec..d00baa55981 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/SearchPanelProvider.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/SearchPanelProvider.java @@ -519,7 +519,7 @@ public final class SearchPanelProvider implements SearchTabOperator { operatorRegistry .get(SimilarityTabOperator.class) .map(SimilarityTabOperator::getConfig) - .orElse(new SimilarityConfig.Builder().build()); + .orElseGet(() -> new SimilarityConfig.Builder().build()); Sort sort = operatorRegistry.get(SortTabOperator.class).map(SortTabOperator::getSort).orElse(null); Set fieldsToLoad = @@ -562,12 +562,12 @@ public final class SearchPanelProvider implements SearchTabOperator { operatorRegistry .get(MLTTabOperator.class) .map(MLTTabOperator::getConfig) - .orElse(new MLTConfig.Builder().build()); + .orElseGet(() -> new MLTConfig.Builder().build()); Analyzer analyzer = operatorRegistry .get(AnalysisTabOperator.class) .map(AnalysisTabOperator::getCurrentAnalyzer) - .orElse(new StandardAnalyzer()); + .orElseGet(StandardAnalyzer::new); Query query = searchModel.mltQuery(docNum, mltConfig, analyzer); Set fieldsToLoad = operatorRegistry @@ -602,12 +602,12 @@ public final class SearchPanelProvider implements SearchTabOperator { operatorRegistry .get(QueryParserTabOperator.class) .map(QueryParserTabOperator::getConfig) - .orElse(new QueryParserConfig.Builder().build()); + .orElseGet(() -> new QueryParserConfig.Builder().build()); Analyzer analyzer = operatorRegistry .get(AnalysisTabOperator.class) .map(AnalysisTabOperator::getCurrentAnalyzer) - .orElse(new StandardAnalyzer()); + .orElseGet(StandardAnalyzer::new); return searchModel.parseQuery(expr, df, analyzer, config, rewrite); } diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/documents/AddDocumentDialogFactory.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/documents/AddDocumentDialogFactory.java index b49ef949cb5..a1a66d144e0 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/documents/AddDocumentDialogFactory.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/documents/AddDocumentDialogFactory.java @@ -457,7 +457,7 @@ public final class AddDocumentDialogFactory operatorRegistry .get(AnalysisTabOperator.class) .map(AnalysisTabOperator::getCurrentAnalyzer) - .orElse(new StandardAnalyzer()); + .orElseGet(StandardAnalyzer::new); toolsModel.addDocument(doc, analyzer); indexHandler.reOpen(); operatorRegistry diff --git a/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java b/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java index 3fc46305dde..7f5136a2dd8 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java @@ -163,7 +163,7 @@ public final class AnalysisImpl implements Analysis { config .getConfigDir() .map(path -> CustomAnalyzer.builder(FileSystems.getDefault().getPath(path))) - .orElse(CustomAnalyzer.builder()); + .orElseGet(CustomAnalyzer::builder); // set tokenizer builder.withTokenizer(