Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: src/core/SkString.cpp

Issue 679433003: Possible optimization to SkString (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: assert cleanup Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkString.cpp
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index 48459dbbd8ac69eabb6f2f72cbbf1c9ff862e7f5..d3a28e248bf7e864c88e751d1a2ce2e0d8f9f8ff 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -26,12 +26,13 @@ static const size_t kBufferSize = 1024;
#define SNPRINTF snprintf
#endif
-#define ARGS_TO_BUFFER(format, buffer, size) \
- do { \
- va_list args; \
- va_start(args, format); \
- VSNPRINTF(buffer, size, format, args); \
- va_end(args); \
+#define ARGS_TO_BUFFER(format, buffer, size, written) \
+ do { \
+ va_list args; \
+ va_start(args, format); \
+ written = VSNPRINTF(buffer, size, format, args); \
+ SkASSERT(written >= 0 && written < SkToInt(size)); \
+ va_end(args); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
@@ -557,37 +558,42 @@ void SkString::insertScalar(size_t offset, SkScalar value) {
void SkString::printf(const char format[], ...) {
char buffer[kBufferSize];
- ARGS_TO_BUFFER(format, buffer, kBufferSize);
+ int length;
+ ARGS_TO_BUFFER(format, buffer, kBufferSize, length);
- this->set(buffer, strlen(buffer));
+ this->set(buffer, length);
}
void SkString::appendf(const char format[], ...) {
char buffer[kBufferSize];
- ARGS_TO_BUFFER(format, buffer, kBufferSize);
+ int length;
+ ARGS_TO_BUFFER(format, buffer, kBufferSize, length);
- this->append(buffer, strlen(buffer));
+ this->append(buffer, length);
}
void SkString::appendVAList(const char format[], va_list args) {
char buffer[kBufferSize];
- VSNPRINTF(buffer, kBufferSize, format, args);
+ int length = VSNPRINTF(buffer, kBufferSize, format, args);
+ SkASSERT(length >= 0 && length < SkToInt(kBufferSize));
- this->append(buffer, strlen(buffer));
+ this->append(buffer, length);
}
void SkString::prependf(const char format[], ...) {
char buffer[kBufferSize];
- ARGS_TO_BUFFER(format, buffer, kBufferSize);
+ int length;
+ ARGS_TO_BUFFER(format, buffer, kBufferSize, length);
- this->prepend(buffer, strlen(buffer));
+ this->prepend(buffer, length);
}
void SkString::prependVAList(const char format[], va_list args) {
char buffer[kBufferSize];
- VSNPRINTF(buffer, kBufferSize, format, args);
+ int length = VSNPRINTF(buffer, kBufferSize, format, args);
+ SkASSERT(length >= 0 && length < SkToInt(kBufferSize));
- this->prepend(buffer, strlen(buffer));
+ this->prepend(buffer, length);
}
@@ -635,7 +641,8 @@ void SkString::swap(SkString& other) {
SkString SkStringPrintf(const char* format, ...) {
SkString formattedOutput;
char buffer[kBufferSize];
- ARGS_TO_BUFFER(format, buffer, kBufferSize);
+ SK_UNUSED int length;
+ ARGS_TO_BUFFER(format, buffer, kBufferSize, length);
formattedOutput.set(buffer);
return formattedOutput;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698