performance: Use startsWith in many places.

Using startsWith is faster than indexOf, especially for long strings
and short prefixes.  It's also a lot more readable.  The only reason
we weren't using it was when a lot of the code was originally written,
it wasn't available.
This commit is contained in:
Steve Howell
2020-01-28 14:26:02 +00:00
committed by Tim Abbott
parent d3e961e179
commit d0453dc8f4
8 changed files with 23 additions and 17 deletions

View File

@@ -25,7 +25,7 @@ function filter_streams_by_search(streams, search_term) {
const cands = lower_stream_name.split(" ");
cands.push(lower_stream_name);
return _.any(cands, function (name) {
return name.indexOf(search_term) === 0;
return name.startsWith(search_term);
});
});
});