Commit 6fd481df authored by Max Kellermann's avatar Max Kellermann

Mapper, ...: use memcmp() instead of strncmp() where appropriate

Micro-optimization.
parent b915e433
...@@ -252,7 +252,7 @@ std::string ...@@ -252,7 +252,7 @@ std::string
map_fs_to_utf8(const char *path_fs) map_fs_to_utf8(const char *path_fs)
{ {
if (!music_dir_fs.IsNull() && if (!music_dir_fs.IsNull() &&
strncmp(path_fs, music_dir_fs.c_str(), music_dir_fs_length) == 0 && memcmp(path_fs, music_dir_fs.data(), music_dir_fs_length) == 0 &&
G_IS_DIR_SEPARATOR(path_fs[music_dir_fs_length])) G_IS_DIR_SEPARATOR(path_fs[music_dir_fs_length]))
/* remove musicDir prefix */ /* remove musicDir prefix */
path_fs += music_dir_fs_length + 1; path_fs += music_dir_fs_length + 1;
......
...@@ -114,7 +114,7 @@ handle_lsinfo(Client *client, int argc, char *argv[]) ...@@ -114,7 +114,7 @@ handle_lsinfo(Client *client, int argc, char *argv[])
/* default is root directory */ /* default is root directory */
uri = ""; uri = "";
if (strncmp(uri, "file:///", 8) == 0) { if (memcmp(uri, "file:///", 8) == 0) {
/* print information about an arbitrary local file */ /* print information about an arbitrary local file */
const char *path_utf8 = uri + 7; const char *path_utf8 = uri + 7;
const Path path_fs = Path::FromUTF8(path_utf8); const Path path_fs = Path::FromUTF8(path_utf8);
......
...@@ -43,7 +43,7 @@ handle_add(Client *client, gcc_unused int argc, char *argv[]) ...@@ -43,7 +43,7 @@ handle_add(Client *client, gcc_unused int argc, char *argv[])
char *uri = argv[1]; char *uri = argv[1];
enum playlist_result result; enum playlist_result result;
if (strncmp(uri, "file:///", 8) == 0) { if (memcmp(uri, "file:///", 8) == 0) {
const char *path_utf8 = uri + 7; const char *path_utf8 = uri + 7;
const Path path_fs = Path::FromUTF8(path_utf8); const Path path_fs = Path::FromUTF8(path_utf8);
...@@ -86,7 +86,7 @@ handle_addid(Client *client, int argc, char *argv[]) ...@@ -86,7 +86,7 @@ handle_addid(Client *client, int argc, char *argv[])
unsigned added_id; unsigned added_id;
enum playlist_result result; enum playlist_result result;
if (strncmp(uri, "file:///", 8) == 0) { if (memcmp(uri, "file:///", 8) == 0) {
const char *path_utf8 = uri + 7; const char *path_utf8 = uri + 7;
const Path path_fs = Path::FromUTF8(path_utf8); const Path path_fs = Path::FromUTF8(path_utf8);
......
...@@ -1084,8 +1084,8 @@ static struct input_stream * ...@@ -1084,8 +1084,8 @@ static struct input_stream *
input_curl_open(const char *url, Mutex &mutex, Cond &cond, input_curl_open(const char *url, Mutex &mutex, Cond &cond,
Error &error) Error &error)
{ {
if ((strncmp(url, "http://", 7) != 0) && if (memcmp(url, "http://", 7) != 0 &&
(strncmp(url, "https://", 8) != 0)) memcmp(url, "https://", 8) != 0)
return NULL; return NULL;
struct input_curl *c = new input_curl(url, mutex, cond); struct input_curl *c = new input_curl(url, mutex, cond);
......
...@@ -78,7 +78,7 @@ HttpdClient::HandleLine(const char *line) ...@@ -78,7 +78,7 @@ HttpdClient::HandleLine(const char *line)
assert(state != RESPONSE); assert(state != RESPONSE);
if (state == REQUEST) { if (state == REQUEST) {
if (strncmp(line, "GET /", 5) != 0) { if (memcmp(line, "GET /", 5) != 0) {
/* only GET is supported */ /* only GET is supported */
LogWarning(httpd_output_domain, LogWarning(httpd_output_domain,
"malformed request line from client"); "malformed request line from client");
...@@ -86,7 +86,7 @@ HttpdClient::HandleLine(const char *line) ...@@ -86,7 +86,7 @@ HttpdClient::HandleLine(const char *line)
} }
line = strchr(line + 5, ' '); line = strchr(line + 5, ' ');
if (line == nullptr || strncmp(line + 1, "HTTP/", 5) != 0) { if (line == nullptr || memcmp(line + 1, "HTTP/", 5) != 0) {
/* HTTP/0.9 without request headers */ /* HTTP/0.9 without request headers */
BeginResponse(); BeginResponse();
return true; return true;
......
...@@ -175,7 +175,7 @@ static int handle_mapkey(void *ctx, const unsigned char* stringval, ...@@ -175,7 +175,7 @@ static int handle_mapkey(void *ctx, const unsigned char* stringval,
data->key = Other; data->key = Other;
for (i = 0; i < Other; ++i) { for (i = 0; i < Other; ++i) {
if (strncmp((const char *)stringval, key_str[i], stringlen) == 0) { if (memcmp((const char *)stringval, key_str[i], stringlen) == 0) {
data->key = i; data->key = i;
break; break;
} }
......
...@@ -86,9 +86,9 @@ uri_remove_auth(const char *uri) ...@@ -86,9 +86,9 @@ uri_remove_auth(const char *uri)
const char *auth, *slash, *at; const char *auth, *slash, *at;
char *p; char *p;
if (strncmp(uri, "http://", 7) == 0) if (memcmp(uri, "http://", 7) == 0)
auth = uri + 7; auth = uri + 7;
else if (strncmp(uri, "https://", 8) == 0) else if (memcmp(uri, "https://", 8) == 0)
auth = uri + 8; auth = uri + 8;
else else
/* unrecognized URI */ /* unrecognized URI */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment