From 1270a61057d3915dedd543428cc65ea05e9439ed Mon Sep 17 00:00:00 2001 From: Brett Stimmerman Date: Tue, 26 Aug 2014 15:14:54 -0700 Subject: [PATCH] Avoid unnecessary clearTimeouts in debounce() debounce() used to return a function that when first invoked always called `clearTimeout` before `setTimeout`, even if there was no timeout to clear. This change adds a guard to prevent such unnecessary `clearTimeout` calls. The performance implications are likely minimal, but the boolean check should perform better in general than what amounts to a noop function call when `timeout` is `null`. As well, devtools timelines will no longer display a not-useful "Remove Timer" scripting blip for unnecessary `clearTimeout`s. --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index b9d04768..476a0e5b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -177,7 +177,7 @@ define( }; var callNow = immediate && !timeout; - clearTimeout(timeout); + timeout && clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) {