From: Daniel Cousens Date: Wed, 22 Apr 2015 00:41:01 +0000 (+1000) Subject: index: dont use empty blocks X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=a2dbe7afb66675139697de2758d46656d3f24538;p=buffer.git index: dont use empty blocks --- diff --git a/index.js b/index.js index a7989ae..28ac51e 100644 --- a/index.js +++ b/index.js @@ -230,11 +230,20 @@ Buffer.compare = function compare (a, b) { var x = a.length var y = b.length - for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} + + var i = 0 + var len = Math.min(x, y) + while (i < len) { + if (a[i] !== b[i]) break + + ++i + } + if (i !== len) { x = a[i] y = b[i] } + if (x < y) return -1 if (y < x) return 1 return 0