Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Since buffers are a few tens of bytes there is no need for optimized memfunctions. For compile time sizes, the compiler will generate optimal code already.
  • Loading branch information
gchatelet committed Nov 22, 2021
1 parent fc52c64 commit 9d34e6a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
16 changes: 1 addition & 15 deletions src/copy.inl
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@
// limitations under the License.

#include <stddef.h>
#include <stdint.h>

static void copy(char *__restrict dst, const char *src, size_t count) {
size_t offset = 0;

#define CHUNK_COPY(TYPE) \
while (count - offset >= sizeof(TYPE)) { \
*(TYPE *)(dst + offset) = *(const TYPE *)(src + offset); \
offset += sizeof(TYPE); \
}

CHUNK_COPY(uint64_t)
CHUNK_COPY(uint32_t)
CHUNK_COPY(uint16_t)
CHUNK_COPY(uint8_t)

#undef CHUNK_COPY
for (size_t i = 0; i < count; ++i) dst[i] = src[i];
}
19 changes: 2 additions & 17 deletions src/equals.inl
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,9 @@

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

static bool equals(const char *lhs, const char *rhs, size_t count) {
size_t offset = 0;

#define CHUNK_EQUALS(TYPE) \
while (count - offset >= sizeof(TYPE)) { \
TYPE l = *(const TYPE *)(lhs + offset); \
TYPE r = *(const TYPE *)(rhs + offset); \
if (l != r) return false; \
offset += sizeof(TYPE); \
}

CHUNK_EQUALS(uint64_t)
CHUNK_EQUALS(uint32_t)
CHUNK_EQUALS(uint16_t)
CHUNK_EQUALS(uint8_t)
#undef CHUNK_EQUALS

for (size_t i = 0; i < count; ++i)
if (lhs[i] != rhs[i]) return false;
return true;
}

0 comments on commit 9d34e6a

Please sign in to comment.