Skip to content

Commit 2fa6376

Browse files
gengjiawenaddaleax
authored andcommitted
src: refactor macro to std::min in node_buffer.cc
PR-URL: #25919 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
1 parent 1aa11e1 commit 2fa6376

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/node_buffer.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include <string.h>
3535
#include <limits.h>
3636

37-
#define MIN(a, b) ((a) < (b) ? (a) : (b))
38-
3937
#define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \
4038
THROW_AND_RETURN_IF_NOT_BUFFER(env, obj, "argument") \
4139

@@ -518,9 +516,9 @@ void Copy(const FunctionCallbackInfo<Value> &args) {
518516
if (source_end - source_start > target_length - target_start)
519517
source_end = source_start + target_length - target_start;
520518

521-
uint32_t to_copy = MIN(MIN(source_end - source_start,
522-
target_length - target_start),
523-
ts_obj_length - source_start);
519+
uint32_t to_copy = std::min(
520+
std::min(source_end - source_start, target_length - target_start),
521+
ts_obj_length - source_start);
524522

525523
memmove(target_data + target_start, ts_obj_data + source_start, to_copy);
526524
args.GetReturnValue().Set(to_copy);
@@ -551,7 +549,8 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
551549
if (Buffer::HasInstance(args[1])) {
552550
SPREAD_BUFFER_ARG(args[1], fill_obj);
553551
str_length = fill_obj_length;
554-
memcpy(ts_obj_data + start, fill_obj_data, MIN(str_length, fill_length));
552+
memcpy(
553+
ts_obj_data + start, fill_obj_data, std::min(str_length, fill_length));
555554
goto start_fill;
556555
}
557556

@@ -572,15 +571,15 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
572571
if (enc == UTF8) {
573572
str_length = str_obj->Utf8Length(env->isolate());
574573
node::Utf8Value str(env->isolate(), args[1]);
575-
memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length));
574+
memcpy(ts_obj_data + start, *str, std::min(str_length, fill_length));
576575

577576
} else if (enc == UCS2) {
578577
str_length = str_obj->Length() * sizeof(uint16_t);
579578
node::TwoByteValue str(env->isolate(), args[1]);
580579
if (IsBigEndian())
581580
SwapBytes16(reinterpret_cast<char*>(&str[0]), str_length);
582581

583-
memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length));
582+
memcpy(ts_obj_data + start, *str, std::min(str_length, fill_length));
584583

585584
} else {
586585
// Write initial String to Buffer, then use that memory to copy remainder
@@ -645,7 +644,7 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
645644
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], ts_obj_length - offset,
646645
&max_length));
647646

648-
max_length = MIN(ts_obj_length - offset, max_length);
647+
max_length = std::min(ts_obj_length - offset, max_length);
649648

650649
if (max_length == 0)
651650
return args.GetReturnValue().Set(0);
@@ -714,9 +713,9 @@ void CompareOffset(const FunctionCallbackInfo<Value> &args) {
714713
CHECK_LE(source_start, source_end);
715714
CHECK_LE(target_start, target_end);
716715

717-
size_t to_cmp = MIN(MIN(source_end - source_start,
718-
target_end - target_start),
719-
ts_obj_length - source_start);
716+
size_t to_cmp =
717+
std::min(std::min(source_end - source_start, target_end - target_start),
718+
ts_obj_length - source_start);
720719

721720
int val = normalizeCompareVal(to_cmp > 0 ?
722721
memcmp(ts_obj_data + source_start,
@@ -736,7 +735,7 @@ void Compare(const FunctionCallbackInfo<Value> &args) {
736735
SPREAD_BUFFER_ARG(args[0], obj_a);
737736
SPREAD_BUFFER_ARG(args[1], obj_b);
738737

739-
size_t cmp_length = MIN(obj_a_length, obj_b_length);
738+
size_t cmp_length = std::min(obj_a_length, obj_b_length);
740739

741740
int val = normalizeCompareVal(cmp_length > 0 ?
742741
memcmp(obj_a_data, obj_b_data, cmp_length) : 0,

0 commit comments

Comments
 (0)