Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).

This commit is contained in:
Sam Lantinga
2013-08-29 08:30:21 -07:00
parent 3e2930defe
commit e07d7e649c
12 changed files with 43 additions and 43 deletions

View File

@@ -109,17 +109,17 @@ SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iter
Uint32 entireStringLength;
char *buffer;
if (runSeed == NULL || SDL_strlen(runSeed)==0) {
if (runSeed == NULL || runSeed[0] == '\0') {
SDLTest_LogError("Invalid runSeed string.");
return -1;
}
if (suiteName == NULL || SDL_strlen(suiteName)==0) {
if (suiteName == NULL || suiteName[0] == '\0') {
SDLTest_LogError("Invalid suiteName string.");
return -1;
}
if (testName == NULL || SDL_strlen(testName)==0) {
if (testName == NULL || testName[0] == '\0') {
SDLTest_LogError("Invalid testName string.");
return -1;
}
@@ -399,7 +399,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
}
/* Generate run see if we don't have one already */
if (userRunSeed == NULL || SDL_strlen(userRunSeed) == 0) {
if (userRunSeed == NULL || userRunSeed[0] == '\0') {
runSeed = SDLTest_GenerateRunSeed(16);
if (runSeed == NULL) {
SDLTest_LogError("Generating a random seed failed");
@@ -422,7 +422,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
/* Initialize filtering */
if (filter != NULL && SDL_strlen(filter) > 0) {
if (filter != NULL && filter[0] != '\0') {
/* Loop over all suites to check if we have a filter match */
suiteCounter = 0;
while (testSuites[suiteCounter] && suiteFilter == 0) {
@@ -521,7 +521,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
suiteCounter,
testCounter,
currentTestName);
if (testCase->description != NULL && SDL_strlen(testCase->description)>0) {
if (testCase->description != NULL && testCase->description[0] != '\0') {
SDLTest_Log("Test Description: '%s'",
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
}

View File

@@ -65,7 +65,7 @@ SDL_HasClipboardText(void)
if (_this->HasClipboardText) {
return _this->HasClipboardText(_this);
} else {
if ((_this->clipboard_text) && (SDL_strlen(_this->clipboard_text)>0)) {
if (_this->clipboard_text && _this->clipboard_text[0] != '\0') {
return SDL_TRUE;
} else {
return SDL_FALSE;

View File

@@ -1453,7 +1453,7 @@ SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata)
CHECK_WINDOW_MAGIC(window, NULL);
/* Input validation */
if (name == NULL || SDL_strlen(name) == 0) {
if (name == NULL || name[0] == '\0') {
SDL_InvalidParamError("name");
return NULL;
}
@@ -1500,7 +1500,7 @@ SDL_GetWindowData(SDL_Window * window, const char *name)
CHECK_WINDOW_MAGIC(window, NULL);
/* Input validation */
if (name == NULL || SDL_strlen(name) == 0) {
if (name == NULL || name[0] == '\0') {
SDL_InvalidParamError("name");
return NULL;
}

View File

@@ -82,7 +82,7 @@ SDL_bool BE_HasClipboardText(_THIS) {
SDL_bool result = SDL_FALSE;
char *text = BE_GetClipboardText(_this);
if (text) {
result = (SDL_strlen(text)>0) ? SDL_TRUE : SDL_FALSE;
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
}
return result;

View File

@@ -95,7 +95,7 @@ Cocoa_HasClipboardText(_THIS)
SDL_bool result = SDL_FALSE;
char *text = Cocoa_GetClipboardText(_this);
if (text) {
result = (SDL_strlen(text)>0) ? SDL_TRUE : SDL_FALSE;
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
}
return result;

View File

@@ -137,7 +137,7 @@ WIN_HasClipboardText(_THIS)
SDL_bool result = SDL_FALSE;
char *text = WIN_GetClipboardText(_this);
if (text) {
result = (SDL_strlen(text)>0) ? SDL_TRUE : SDL_FALSE;
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
}
return result;

View File

@@ -165,7 +165,7 @@ X11_HasClipboardText(_THIS)
SDL_bool result = SDL_FALSE;
char *text = X11_GetClipboardText(_this);
if (text) {
result = (SDL_strlen(text)>0) ? SDL_TRUE : SDL_FALSE;
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
}
return result;