/*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
static really_inline
int cmpNocaseNaive(const u8 *p1, const u8 *p2, size_t len) {
- const u8 *pEnd = (const u8 *)p1 + len;
+ const u8 *pEnd = p1 + len;
for (; p1 < pEnd; p1++, p2++) {
- if (mytolower(*p1) != mytolower(*p2)) {
+ assert(!ourisalpha(*p2) || myisupper(*p2)); // Already upper-case.
+ if ((u8)mytoupper(*p1) != *p2) {
return 1;
}
}
static really_inline
int cmpCaseNaive(const u8 *p1, const u8 *p2, size_t len) {
- const u8 *pEnd = (const u8 *)p1 + len;
+ const u8 *pEnd = p1 + len;
for (; p1 < pEnd; p1++, p2++) {
if (*p1 != *p2) {
return 1;
#define CMP_SIZE sizeof(CMP_T)
+/**
+ * \brief Compare two strings, optionally caselessly.
+ *
+ * Note: If nocase is true, p2 is assumed to be already upper-case.
+ */
#if defined(ARCH_IA32)
static UNUSED never_inline
#else
if (nocase) { // Case-insensitive version.
for (; p1 < p1_end; p1 += CMP_SIZE, p2 += CMP_SIZE) {
- if (TOUPPER(ULOAD(p1)) != TOUPPER(ULOAD(p2))) {
+ assert(ULOAD(p2) == TOUPPER(ULOAD(p2))); // Already upper-case.
+ if (TOUPPER(ULOAD(p1)) != ULOAD(p2)) {
return 1;
}
}
- if (TOUPPER(ULOAD(p1_end)) != TOUPPER(ULOAD(p2_end))) {
+ assert(ULOAD(p2_end) == TOUPPER(ULOAD(p2_end))); // Already upper-case.
+ if (TOUPPER(ULOAD(p1_end)) != ULOAD(p2_end)) {
return 1;
}
} else { // Case-sensitive version.