1
0

fwrite_le.c: optimize for step or size equal to 1

This commit is contained in:
Intel A80486DX2-66 2024-05-19 14:23:50 +03:00
parent 9495b0a23e
commit 12b85ce454
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -16,6 +16,11 @@ void reorder_le_be(
uint8_t* bytes,
#endif
size_t count, size_t step) {
if (step == 1) {
return;
}
for (size_t i = 0; i < count; i += step) {
const size_t div_size = step / 2;
for (size_t j = 0; j < div_size; j++) {
@ -41,11 +46,12 @@ size_t fwrite_le(void* ptr, size_t size, size_t count, FILE* stream) {
return 0;
int endianness = detect_endianness();
if (endianness == UNSUPPORTED_ENDIANNESS) {
if (size == 1 || endianness == DETECTED_LITTLE_ENDIAN)
return fwrite(ptr, size, count, stream);
else if (endianness == UNSUPPORTED_ENDIANNESS) {
fprintf(stderr, "Unsupported endianness\n");
exit(EXIT_FAILURE);
} else if (endianness == DETECTED_LITTLE_ENDIAN)
return fwrite(ptr, size, count, stream);
}
// case: big-endian
size_t bytes_count = size * count;