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

Micro-optimization.
This commit is contained in:
Max Kellermann 2013-10-14 22:00:21 +02:00
parent b915e43391
commit 6fd481df97
7 changed files with 11 additions and 11 deletions

View File

@ -252,7 +252,7 @@ std::string
map_fs_to_utf8(const char *path_fs)
{
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]))
/* remove musicDir prefix */
path_fs += music_dir_fs_length + 1;

View File

@ -114,7 +114,7 @@ handle_lsinfo(Client *client, int argc, char *argv[])
/* default is root directory */
uri = "";
if (strncmp(uri, "file:///", 8) == 0) {
if (memcmp(uri, "file:///", 8) == 0) {
/* print information about an arbitrary local file */
const char *path_utf8 = uri + 7;
const Path path_fs = Path::FromUTF8(path_utf8);

View File

@ -43,7 +43,7 @@ handle_add(Client *client, gcc_unused int argc, char *argv[])
char *uri = argv[1];
enum playlist_result result;
if (strncmp(uri, "file:///", 8) == 0) {
if (memcmp(uri, "file:///", 8) == 0) {
const char *path_utf8 = uri + 7;
const Path path_fs = Path::FromUTF8(path_utf8);
@ -86,7 +86,7 @@ handle_addid(Client *client, int argc, char *argv[])
unsigned added_id;
enum playlist_result result;
if (strncmp(uri, "file:///", 8) == 0) {
if (memcmp(uri, "file:///", 8) == 0) {
const char *path_utf8 = uri + 7;
const Path path_fs = Path::FromUTF8(path_utf8);

View File

@ -1084,8 +1084,8 @@ static struct input_stream *
input_curl_open(const char *url, Mutex &mutex, Cond &cond,
Error &error)
{
if ((strncmp(url, "http://", 7) != 0) &&
(strncmp(url, "https://", 8) != 0))
if (memcmp(url, "http://", 7) != 0 &&
memcmp(url, "https://", 8) != 0)
return NULL;
struct input_curl *c = new input_curl(url, mutex, cond);

View File

@ -78,7 +78,7 @@ HttpdClient::HandleLine(const char *line)
assert(state != RESPONSE);
if (state == REQUEST) {
if (strncmp(line, "GET /", 5) != 0) {
if (memcmp(line, "GET /", 5) != 0) {
/* only GET is supported */
LogWarning(httpd_output_domain,
"malformed request line from client");
@ -86,7 +86,7 @@ HttpdClient::HandleLine(const char *line)
}
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 */
BeginResponse();
return true;

View File

@ -175,7 +175,7 @@ static int handle_mapkey(void *ctx, const unsigned char* stringval,
data->key = Other;
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;
break;
}

View File

@ -86,9 +86,9 @@ uri_remove_auth(const char *uri)
const char *auth, *slash, *at;
char *p;
if (strncmp(uri, "http://", 7) == 0)
if (memcmp(uri, "http://", 7) == 0)
auth = uri + 7;
else if (strncmp(uri, "https://", 8) == 0)
else if (memcmp(uri, "https://", 8) == 0)
auth = uri + 8;
else
/* unrecognized URI */