From 1aa93dfea2e8dc7b48a4f65af1fba6b3da1335be Mon Sep 17 00:00:00 2001 From: blankie Date: Mon, 23 Jan 2023 21:29:37 +0700 Subject: [PATCH] Use strncmp --- logcat_entry.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/logcat_entry.cpp b/logcat_entry.cpp index 0d88c0d..119967b 100644 --- a/logcat_entry.cpp +++ b/logcat_entry.cpp @@ -102,10 +102,6 @@ std::optional try_parse_logcat_entry(char* buf, size_t length, Buff return std::move(logcat_entry); } -static bool substr_equal(const char* lhs_str, size_t lhs_length, const char* rhs_str) { - return lhs_length == strlen(rhs_str) && memcmp(lhs_str, rhs_str, lhs_length * sizeof(char)) == 0; -} - std::optional try_parse_buffer(char* buf, size_t length) { regmatch_t matches[2]; matches[0].rm_so = 0; @@ -119,11 +115,10 @@ std::optional try_parse_buffer(char* buf, size_t length) { } const char* buffer_str = &buf[matches[1].rm_so]; - size_t buffer_length = static_cast(matches[1].rm_eo - matches[1].rm_so); - if (substr_equal(buffer_str, buffer_length, "main")) return Buffer::Main; - if (substr_equal(buffer_str, buffer_length, "system")) return Buffer::System; - if (substr_equal(buffer_str, buffer_length, "radio")) return Buffer::Radio; - if (substr_equal(buffer_str, buffer_length, "events")) return Buffer::Events; - if (substr_equal(buffer_str, buffer_length, "crash")) return Buffer::Crash; + if (!strncmp(buffer_str, "main", 4)) return Buffer::Main; + if (!strncmp(buffer_str, "system", 6)) return Buffer::System; + if (!strncmp(buffer_str, "radio", 5)) return Buffer::Radio; + if (!strncmp(buffer_str, "events", 6)) return Buffer::Events; + if (!strncmp(buffer_str, "crash", 5)) return Buffer::Crash; return Buffer::Unknown; }