From: dimhotepus Date: Sat, 30 Apr 2016 11:24:12 +0000 (+0300) Subject: Cache strlen outside of cycles (PVS-Studio) X-Git-Tag: accepted/tizen/5.0/unified/20181102.024921~21^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4544e968abe7ced002713650c02d909672a8aa4c;p=platform%2Fupstream%2Fglog.git Cache strlen outside of cycles (PVS-Studio) --- diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index b886222..b9b8357 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -768,17 +768,18 @@ static void TestOneTruncate(const char *path, int64 limit, int64 keep, CHECK_ERR(fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)); const char *discardstr = "DISCARDME!", *keepstr = "KEEPME!"; + const size_t discard_size = strlen(discardstr), keep_size = strlen(keepstr); // Fill the file with the requested data; first discard data, then kept data int64 written = 0; while (written < dsize) { - int bytes = min(dsize - written, strlen(discardstr)); + int bytes = min(dsize - written, discard_size); CHECK_ERR(write(fd, discardstr, bytes)); written += bytes; } written = 0; while (written < ksize) { - int bytes = min(ksize - written, strlen(keepstr)); + int bytes = min(ksize - written, keep_size); CHECK_ERR(write(fd, keepstr, bytes)); written += bytes; } @@ -800,7 +801,7 @@ static void TestOneTruncate(const char *path, int64 limit, int64 keep, const char *p = buf; int64 checked = 0; while (checked < expect) { - int bytes = min(expect - checked, strlen(keepstr)); + int bytes = min(expect - checked, keep_size); CHECK(!memcmp(p, keepstr, bytes)); checked += bytes; }