Remove mempcpy for portability

This commit is contained in:
Bruce Hill 2025-03-27 17:33:47 -04:00
parent 3c52a75633
commit b5c6a3ec62
2 changed files with 31 additions and 17 deletions

View File

@ -131,28 +131,37 @@ public void Array$insert_all(Array_t *arr, Array_t to_insert, Int_t int_index, i
// Copy first chunk of `arr` if needed:
if (index > 1) {
if (arr->stride == padded_item_size) {
p = mempcpy(p, arr->data, (size_t)((index-1)*padded_item_size));
memcpy(p, arr->data, (size_t)((index-1)*padded_item_size));
p += (index-1)*padded_item_size;
} else {
for (int64_t i = 0; i < index-1; i++)
p = mempcpy(p, arr->data + arr->stride*i, (size_t)padded_item_size);
for (int64_t i = 0; i < index-1; i++) {
memcpy(p, arr->data + arr->stride*i, (size_t)padded_item_size);
p += padded_item_size;
}
}
}
// Copy `to_insert`
if (to_insert.stride == padded_item_size) {
p = mempcpy(p, to_insert.data, (size_t)(to_insert.length*padded_item_size));
memcpy(p, to_insert.data, (size_t)(to_insert.length*padded_item_size));
p += to_insert.length*padded_item_size;
} else {
for (int64_t i = 0; i < index-1; i++)
p = mempcpy(p, to_insert.data + to_insert.stride*i, (size_t)padded_item_size);
for (int64_t i = 0; i < index-1; i++) {
memcpy(p, to_insert.data + to_insert.stride*i, (size_t)padded_item_size);
p += padded_item_size;
}
}
// Copy last chunk of `arr` if needed:
if (index < arr->length + 1) {
if (arr->stride == padded_item_size) {
p = mempcpy(p, arr->data + padded_item_size*(index-1), (size_t)((arr->length - index + 1)*padded_item_size));
memcpy(p, arr->data + padded_item_size*(index-1), (size_t)((arr->length - index + 1)*padded_item_size));
p += (arr->length - index + 1)*padded_item_size;
} else {
for (int64_t i = index-1; i < arr->length-1; i++)
p = mempcpy(p, arr->data + arr->stride*i, (size_t)padded_item_size);
for (int64_t i = index-1; i < arr->length-1; i++) {
memcpy(p, arr->data + arr->stride*i, (size_t)padded_item_size);
p += padded_item_size;
}
}
}
arr->length = new_len;

View File

@ -191,7 +191,7 @@ public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_le
// Copy length-prefixed UTF32 codepoints into the arena and store where they live:
ucs4_t *codepoint_copy = arena;
mempcpy(codepoint_copy, length_prefixed, sizeof(ucs4_t[1+utf32_len]));
memcpy(codepoint_copy, length_prefixed, sizeof(ucs4_t[1+utf32_len]));
synthetic_graphemes[-grapheme_id-1].utf32_cluster = codepoint_copy;
arena += sizeof(ucs4_t[1+utf32_len]);
@ -405,7 +405,8 @@ static Text_t concat2_assuming_safe(Text_t a, Text_t b)
ret.graphemes = GC_MALLOC_ATOMIC(sizeof(int32_t[ret.length]));
int32_t *dest = (int32_t*)ret.graphemes;
if (a.tag == TEXT_GRAPHEMES) {
dest = mempcpy(dest, a.graphemes, sizeof(int32_t[a.length]));
memcpy(dest, a.graphemes, sizeof(int32_t[a.length]));
dest += a.length;
} else {
for (int64_t i = 0; i < a.length; i++)
*(dest++) = (int32_t)a.ascii[i];
@ -443,15 +444,19 @@ static Text_t concat2(Text_t a, Text_t b)
ucs4_t codepoints[len];
ucs4_t *dest = codepoints;
if (last_a < 0)
dest = mempcpy(dest, GRAPHEME_CODEPOINTS(last_a), sizeof(ucs4_t[NUM_GRAPHEME_CODEPOINTS(last_a)]));
else
if (last_a < 0) {
memcpy(dest, GRAPHEME_CODEPOINTS(last_a), sizeof(ucs4_t[NUM_GRAPHEME_CODEPOINTS(last_a)]));
dest += NUM_GRAPHEME_CODEPOINTS(last_a);
} else {
*(dest++) = (ucs4_t)last_a;
}
if (first_b < 0)
dest = mempcpy(dest, GRAPHEME_CODEPOINTS(first_b), sizeof(ucs4_t[NUM_GRAPHEME_CODEPOINTS(first_b)]));
else
if (first_b < 0) {
memcpy(dest, GRAPHEME_CODEPOINTS(first_b), sizeof(ucs4_t[NUM_GRAPHEME_CODEPOINTS(first_b)]));
dest += NUM_GRAPHEME_CODEPOINTS(first_b);
} else {
*(dest++) = (ucs4_t)first_b;
}
// Do a normalization run for these two codepoints and see if it looks different.
// Normalization should not exceed 3x in the input length (but if it does, it will be