From 414766ee02818244573cd40b9b8b740415984dce Mon Sep 17 00:00:00 2001 From: Stephen Wade Date: Wed, 19 May 2021 23:10:19 -0400 Subject: [PATCH] Chore: Simplify search code --- lib/source-code/token-store/utils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/source-code/token-store/utils.js b/lib/source-code/token-store/utils.js index b65c7347ab0..a2bd77de71a 100644 --- a/lib/source-code/token-store/utils.js +++ b/lib/source-code/token-store/utils.js @@ -23,15 +23,14 @@ function getStartLocation(token) { //------------------------------------------------------------------------------ /** - * Binary-searches the index of the first token which is after the given location. + * Finds the index of the first token which is after the given location. * If it was not found, this returns `tokens.length`. * @param {(Token|Comment)[]} tokens It searches the token in this list. * @param {number} location The location to search. * @returns {number} The found index or `tokens.length`. */ exports.search = function search(tokens, location) { - const val = getStartLocation({ range: [location] }); - const index = tokens.findIndex(el => val <= getStartLocation(el)); + const index = tokens.findIndex(el => location <= getStartLocation(el)); return index === -1 ? tokens.length : index; };