From 83509c6ce0c8039dfb30ee7abb5204fdb0c8571e Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 11 Sep 2019 13:49:25 -0400 Subject: [PATCH] Move static arrays out of function calls This has been shown to slightly improve performance in microbenchmarks https://jsperf.com/leaf-queries-perf/1 --- lib/leaf/match.js | 24 +++++++++++++----------- view/leaf/match_phrase.js | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/leaf/match.js b/lib/leaf/match.js index 08350b3..8cc81ba 100644 --- a/lib/leaf/match.js +++ b/lib/leaf/match.js @@ -1,3 +1,16 @@ +const optional_params = [ + 'boost', + 'operator', + 'analyzer', + 'cutoff_frequency', + 'fuzziness', + 'max_expansions', + 'prefix_length', + 'fuzzy_transpositions', + 'minimum_should_match', + 'zero_terms_query' +]; + module.exports = function( property, value, params) { if( !property || !value) { return null; @@ -11,17 +24,6 @@ module.exports = function( property, value, params) { } }; - const optional_params = ['boost', - 'operator', - 'analyzer', - 'cutoff_frequency', - 'fuzziness', - 'max_expansions', - 'prefix_length', - 'fuzzy_transpositions', - 'minimum_should_match', - 'zero_terms_query']; - optional_params.forEach(function(param) { if (params && params[param]) { query.match[property][param] = params[param]; diff --git a/view/leaf/match_phrase.js b/view/leaf/match_phrase.js index 4a0b19e..a750b2e 100644 --- a/view/leaf/match_phrase.js +++ b/view/leaf/match_phrase.js @@ -1,5 +1,7 @@ const match_phrase = require('../../lib/leaf/match_phrase'); +const optional_params = ['boost', 'slop', 'analyzer']; + module.exports = function( prefix ){ return function( vs ){ @@ -13,8 +15,6 @@ module.exports = function( prefix ){ const options = { }; - const optional_params = ['boost', 'slop', 'analyzer']; - optional_params.forEach(function(param) { const variable_name = `match_phrase:${prefix}:${param}`; if (vs.isset(variable_name)) {