Skip to content

Commit

Permalink
Move static arrays out of function calls
Browse files Browse the repository at this point in the history
This has been shown to slightly improve performance in microbenchmarks

https://jsperf.com/leaf-queries-perf/1
  • Loading branch information
orangejulius committed Sep 11, 2019
1 parent b650df8 commit 83509c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions lib/leaf/match.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions view/leaf/match_phrase.js
Original file line number Diff line number Diff line change
@@ -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 ){

Expand All @@ -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)) {
Expand Down

0 comments on commit 83509c6

Please sign in to comment.