mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
src: only memcmp if length > 0 in Buffer::Compare
Both pointer arguments to memcmp are defined as non-null and compiler optimizes upon that. PR-URL: https://github.com/nodejs/node/pull/2544 Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com> Reviewed-By: thefourtheye - Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
1 parent
c7351db6dc
commit
0357c8fc71
2 files changed
+4
-1
No files matched your search
+1
-1
@@ -835,7 +835,7 @@ void Compare(const FunctionCallbackInfo<Value> &args) {
|
||||
|
||||
size_t cmp_length = MIN(obj_a_length, obj_b_length);
|
||||
|
||||
int32_t val = memcmp(obj_a_data, obj_b_data, cmp_length);
|
||||
int val = cmp_length > 0 ? memcmp(obj_a_data, obj_b_data, cmp_length) : 0;
|
||||
|
||||
// Normalize val to be an integer in the range of [1, -1] since
|
||||
// implementations of memcmp() can vary by platform.
|
||||
|
||||
Reference in new issue
Block a user