From e03cb3f4d16265fe1609862b5f2a613952c20a6a Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Thu, 2 Feb 2017 00:54:21 +0100 Subject: [PATCH] devtools: rewrite SDK.TextSourceMap.findEntry the code was probably correct, I was just haunted by paranormal events issue #53 --- .../devtools/front_end/sdk/SourceMap.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/resources/unpacked/devtools/front_end/sdk/SourceMap.js b/resources/unpacked/devtools/front_end/sdk/SourceMap.js index 537b50a84c..1bf78db4c1 100644 --- a/resources/unpacked/devtools/front_end/sdk/SourceMap.js +++ b/resources/unpacked/devtools/front_end/sdk/SourceMap.js @@ -323,22 +323,22 @@ SDK.TextSourceMap = class { * @return {?SDK.SourceMapEntry} */ findEntry(lineNumber, columnNumber) { - var first = 0; - var mappings = this.mappings(); - var count = mappings.length; - while (count > 1) { - var step = count >> 1; - var middle = first + step; - var mapping = mappings[middle]; - if (lineNumber < mapping.lineNumber || - (lineNumber === mapping.lineNumber && columnNumber < mapping.columnNumber)) { - count = step; + const mappings = this.mappings(); + if (mappings.length <= 0) { + return null; + } + let first = 0; + let last = mappings.length - 1; + while (first < last) { + const middle = first + Math.floor((last + 1 - first) / 2); + const entry = mappings[middle]; + if (lineNumber < entry.lineNumber || (lineNumber === entry.lineNumber && columnNumber < entry.columnNumber)) { + last = middle - 1; } else { first = middle; - count -= step; } } - var entry = mappings[first]; + const entry = mappings[first]; if (entry && entry.lineNumber === lineNumber && entry.columnNumber <= columnNumber) { return entry; } else {