Use orElseGet() to avoid unnecessary object allocation (#13048)

This commit is contained in:
Dmitry Cherniachenko 2024-01-30 00:15:56 +01:00 committed by GitHub
parent d69df16bf8
commit d988f91aba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 7 deletions

View File

@ -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

View File

@ -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<String> 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<String> 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);
}

View File

@ -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

View File

@ -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(