Skip to content

Commit

Permalink
use min and max implementation from the pxt namespace (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedseb authored Sep 20, 2021
1 parent 95ed1a9 commit 9454016
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions libs/base/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int writeBuffer(Buffer buf, int dstOffset, Buffer src, int srcOffset = 0, int le
if (srcOffset < 0 || dstOffset < 0 || dstOffset > buf->length)
return -1;

length = min(src->length - srcOffset, buf->length - dstOffset);
length = pxt::min(src->length - srcOffset, buf->length - dstOffset);

if (length < 0)
return -1;
Expand Down Expand Up @@ -103,7 +103,7 @@ void fill(Buffer buf, int value, int offset = 0, int length = -1) {
return; // DEVICE_INVALID_PARAMETER;
if (length < 0)
length = buf->length;
length = min(length, buf->length - offset);
length = pxt::min(length, buf->length - offset);
memset(buf->data + offset, value, length);
}

Expand All @@ -112,10 +112,10 @@ void fill(Buffer buf, int value, int offset = 0, int length = -1) {
*/
//%
Buffer slice(Buffer buf, int offset = 0, int length = -1) {
offset = min((int)buf->length, offset);
offset = pxt::min((int)buf->length, offset);
if (length < 0)
length = buf->length;
length = min(length, buf->length - offset);
length = pxt::min(length, buf->length - offset);
return mkBuffer(buf->data + offset, length);
}

Expand Down
9 changes: 5 additions & 4 deletions libs/base/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ String substr(String s, int start, int length) {
return mkEmpty();
auto slen = (int)s->getLength();
if (start < 0)
start = max(slen + start, 0);
length = min(length, slen - start);
start = pxt::max(slen + start, 0);
length = pxt::min(length, slen - start);
if (length <= 0)
return mkEmpty();
auto p = s->getUTF8DataAt(start);
Expand Down Expand Up @@ -1875,8 +1875,9 @@ STRING_VT(string_inline_utf8, NOOP, NOOP, 2 + p->utf8.size + 1, p->utf8.data, p-
utf8Len(p->utf8.data, p->utf8.size), utf8Skip(p->utf8.data, p->utf8.size, idx))
STRING_VT(string_skiplist16, NOOP, if (p->skip.list) gcMarkArray(p->skip.list), 2 * sizeof(void *),
PXT_SKIP_DATA_IND(p), p->skip.size, p->skip.length, skipLookup(p, idx, 0))
STRING_VT(string_skiplist16_packed, NOOP, NOOP, 2 + 2 + PXT_NUM_SKIP_ENTRIES(p) * 2 + p->skip.size + 1,
PXT_SKIP_DATA_PACK(p), p->skip.size, p->skip.length, skipLookup(p, idx, 1))
STRING_VT(string_skiplist16_packed, NOOP, NOOP,
2 + 2 + PXT_NUM_SKIP_ENTRIES(p) * 2 + p->skip.size + 1, PXT_SKIP_DATA_PACK(p),
p->skip.size, p->skip.length, skipLookup(p, idx, 1))
STRING_VT(string_cons, fixCons(p), (gcScan((TValue)p->cons.left), gcScan((TValue)p->cons.right)),
2 * sizeof(void *), PXT_SKIP_DATA_IND(p), p->skip.size, p->skip.length,
skipLookup(p, idx, 0))
Expand Down

0 comments on commit 9454016

Please sign in to comment.