1
0
mirror of https://github.com/google/cpu_features.git synced 2025-07-12 02:00:44 +02:00

New code layout - breaking change in cpu_features_macros.h (#194)

This commit helps with platform code separation (fixes #3). It should also help with the build as we can simply include all `impl_*.c` files regardless of OS / arch.

Note: this patch contains breaking changes in `include/cpu_features_macros.h`
 - `CPU_FEATURES_OS_LINUX_OR_ANDROID` does not exist anymore
 - `CPU_FEATURES_OS_FREEBSD`, `CPU_FEATURES_OS_ANDROID` and `CPU_FEATURES_OS_LINUX` are now mutually exclusive (i.e. `CPU_FEATURES_OS_ANDROID` does not imply `CPU_FEATURES_OS_LINUX`)
 - `CPU_FEATURES_OS_DARWIN` has been renamed into `CPU_FEATURES_OS_MACOS` to be able to target non-Mac Apple products (IOS, TV, WATCH). They are now targetable with `CPU_FEATURES_OS_IPHONE`. This matches Apple naming convention described in [this stackoverflow](https://stackoverflow.com/a/49560690).
This commit is contained in:
Guillaume Chatelet
2021-10-28 13:52:46 +02:00
committed by GitHub
parent 0dd8b41eca
commit deb2a61b80
21 changed files with 1296 additions and 1091 deletions

View File

@ -16,11 +16,19 @@
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "copy.h"
#include "equals.h"
static const char* CpuFeatures_memchr(const char* ptr, size_t size, char c) {
for (; ptr && *ptr != '\0'; ++ptr)
if (*ptr == c) return ptr;
return NULL;
}
int CpuFeatures_StringView_IndexOfChar(const StringView view, char c) {
if (view.ptr && view.size) {
const char* const found = (const char*)memchr(view.ptr, c, view.size);
const char* const found = CpuFeatures_memchr(view.ptr, view.size, c);
if (found) {
return (int)(found - view.ptr);
}
@ -48,14 +56,14 @@ int CpuFeatures_StringView_IndexOf(const StringView view,
bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b) {
if (a.size == b.size) {
return a.ptr == b.ptr || memcmp(a.ptr, b.ptr, b.size) == 0;
return a.ptr == b.ptr || equals(a.ptr, b.ptr, b.size);
}
return false;
}
bool CpuFeatures_StringView_StartsWith(const StringView a, const StringView b) {
return a.ptr && b.ptr && b.size && a.size >= b.size
? memcmp(a.ptr, b.ptr, b.size) == 0
? equals(a.ptr, b.ptr, b.size)
: false;
}
@ -138,7 +146,7 @@ void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
const size_t max_copy_size = dst_size - 1;
const size_t copy_size =
src.size > max_copy_size ? max_copy_size : src.size;
memcpy(dst, src.ptr, copy_size);
copy(dst, src.ptr, copy_size);
dst[copy_size] = '\0';
}
}