Possible optimization to SkString
BUG=skia: Review URL: https://codereview.chromium.org/679433003
This commit is contained in:
parent
bf54e49e30
commit
976386b75d
@ -26,11 +26,12 @@ static const size_t kBufferSize = 1024;
|
|||||||
#define SNPRINTF snprintf
|
#define SNPRINTF snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ARGS_TO_BUFFER(format, buffer, size) \
|
#define ARGS_TO_BUFFER(format, buffer, size, written) \
|
||||||
do { \
|
do { \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
va_start(args, format); \
|
va_start(args, format); \
|
||||||
VSNPRINTF(buffer, size, format, args); \
|
written = VSNPRINTF(buffer, size, format, args); \
|
||||||
|
SkASSERT(written >= 0 && written < SkToInt(size)); \
|
||||||
va_end(args); \
|
va_end(args); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -557,37 +558,42 @@ void SkString::insertScalar(size_t offset, SkScalar value) {
|
|||||||
|
|
||||||
void SkString::printf(const char format[], ...) {
|
void SkString::printf(const char format[], ...) {
|
||||||
char buffer[kBufferSize];
|
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[], ...) {
|
void SkString::appendf(const char format[], ...) {
|
||||||
char buffer[kBufferSize];
|
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) {
|
void SkString::appendVAList(const char format[], va_list args) {
|
||||||
char buffer[kBufferSize];
|
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[], ...) {
|
void SkString::prependf(const char format[], ...) {
|
||||||
char buffer[kBufferSize];
|
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) {
|
void SkString::prependVAList(const char format[], va_list args) {
|
||||||
char buffer[kBufferSize];
|
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 SkStringPrintf(const char* format, ...) {
|
||||||
SkString formattedOutput;
|
SkString formattedOutput;
|
||||||
char buffer[kBufferSize];
|
char buffer[kBufferSize];
|
||||||
ARGS_TO_BUFFER(format, buffer, kBufferSize);
|
SK_UNUSED int length;
|
||||||
|
ARGS_TO_BUFFER(format, buffer, kBufferSize, length);
|
||||||
formattedOutput.set(buffer);
|
formattedOutput.set(buffer);
|
||||||
return formattedOutput;
|
return formattedOutput;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user