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#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 ======================= ======================== Lucene 9.9.2 =======================
Bug Fixes Bug Fixes

View File

@ -519,7 +519,7 @@ public final class SearchPanelProvider implements SearchTabOperator {
operatorRegistry operatorRegistry
.get(SimilarityTabOperator.class) .get(SimilarityTabOperator.class)
.map(SimilarityTabOperator::getConfig) .map(SimilarityTabOperator::getConfig)
.orElse(new SimilarityConfig.Builder().build()); .orElseGet(() -> new SimilarityConfig.Builder().build());
Sort sort = Sort sort =
operatorRegistry.get(SortTabOperator.class).map(SortTabOperator::getSort).orElse(null); operatorRegistry.get(SortTabOperator.class).map(SortTabOperator::getSort).orElse(null);
Set<String> fieldsToLoad = Set<String> fieldsToLoad =
@ -562,12 +562,12 @@ public final class SearchPanelProvider implements SearchTabOperator {
operatorRegistry operatorRegistry
.get(MLTTabOperator.class) .get(MLTTabOperator.class)
.map(MLTTabOperator::getConfig) .map(MLTTabOperator::getConfig)
.orElse(new MLTConfig.Builder().build()); .orElseGet(() -> new MLTConfig.Builder().build());
Analyzer analyzer = Analyzer analyzer =
operatorRegistry operatorRegistry
.get(AnalysisTabOperator.class) .get(AnalysisTabOperator.class)
.map(AnalysisTabOperator::getCurrentAnalyzer) .map(AnalysisTabOperator::getCurrentAnalyzer)
.orElse(new StandardAnalyzer()); .orElseGet(StandardAnalyzer::new);
Query query = searchModel.mltQuery(docNum, mltConfig, analyzer); Query query = searchModel.mltQuery(docNum, mltConfig, analyzer);
Set<String> fieldsToLoad = Set<String> fieldsToLoad =
operatorRegistry operatorRegistry
@ -602,12 +602,12 @@ public final class SearchPanelProvider implements SearchTabOperator {
operatorRegistry operatorRegistry
.get(QueryParserTabOperator.class) .get(QueryParserTabOperator.class)
.map(QueryParserTabOperator::getConfig) .map(QueryParserTabOperator::getConfig)
.orElse(new QueryParserConfig.Builder().build()); .orElseGet(() -> new QueryParserConfig.Builder().build());
Analyzer analyzer = Analyzer analyzer =
operatorRegistry operatorRegistry
.get(AnalysisTabOperator.class) .get(AnalysisTabOperator.class)
.map(AnalysisTabOperator::getCurrentAnalyzer) .map(AnalysisTabOperator::getCurrentAnalyzer)
.orElse(new StandardAnalyzer()); .orElseGet(StandardAnalyzer::new);
return searchModel.parseQuery(expr, df, analyzer, config, rewrite); return searchModel.parseQuery(expr, df, analyzer, config, rewrite);
} }

View File

@ -457,7 +457,7 @@ public final class AddDocumentDialogFactory
operatorRegistry operatorRegistry
.get(AnalysisTabOperator.class) .get(AnalysisTabOperator.class)
.map(AnalysisTabOperator::getCurrentAnalyzer) .map(AnalysisTabOperator::getCurrentAnalyzer)
.orElse(new StandardAnalyzer()); .orElseGet(StandardAnalyzer::new);
toolsModel.addDocument(doc, analyzer); toolsModel.addDocument(doc, analyzer);
indexHandler.reOpen(); indexHandler.reOpen();
operatorRegistry operatorRegistry

View File

@ -163,7 +163,7 @@ public final class AnalysisImpl implements Analysis {
config config
.getConfigDir() .getConfigDir()
.map(path -> CustomAnalyzer.builder(FileSystems.getDefault().getPath(path))) .map(path -> CustomAnalyzer.builder(FileSystems.getDefault().getPath(path)))
.orElse(CustomAnalyzer.builder()); .orElseGet(CustomAnalyzer::builder);
// set tokenizer // set tokenizer
builder.withTokenizer( builder.withTokenizer(