Remove unnecessary macros from SkString header.
They have been replaced with equivalent constants (and given the requisite k prefix). Change-Id: I70907eec234e0861cc97aac1ca03086faca42f9a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306160 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
parent
a84caa3a5f
commit
9119625aae
@ -42,6 +42,9 @@ Milestone 86
|
||||
check (via GrRecordingContext::asDirectContext) if the available recording context is actually
|
||||
a direct context.
|
||||
|
||||
* Replace #defined values in SkString with equivalent constexprs.
|
||||
http://review.skia.org/306160
|
||||
|
||||
* * *
|
||||
|
||||
Milestone 85
|
||||
|
@ -63,30 +63,30 @@ static inline bool SkStrContains(const char string[], const char subchar) {
|
||||
|
||||
/*
|
||||
* The SkStrAppend... methods will write into the provided buffer, assuming it is large enough.
|
||||
* Each method has an associated const (e.g. SkStrAppendU32_MaxSize) which will be the largest
|
||||
* Each method has an associated const (e.g. kSkStrAppendU32_MaxSize) which will be the largest
|
||||
* value needed for that method's buffer.
|
||||
*
|
||||
* char storage[SkStrAppendU32_MaxSize];
|
||||
* char storage[kSkStrAppendU32_MaxSize];
|
||||
* SkStrAppendU32(storage, value);
|
||||
*
|
||||
* Note : none of the SkStrAppend... methods write a terminating 0 to their buffers. Instead,
|
||||
* the methods return the ptr to the end of the written part of the buffer. This can be used
|
||||
* to compute the length, and/or know where to write a 0 if that is desired.
|
||||
*
|
||||
* char storage[SkStrAppendU32_MaxSize + 1];
|
||||
* char storage[kSkStrAppendU32_MaxSize + 1];
|
||||
* char* stop = SkStrAppendU32(storage, value);
|
||||
* size_t len = stop - storage;
|
||||
* *stop = 0; // valid, since storage was 1 byte larger than the max.
|
||||
*/
|
||||
|
||||
#define SkStrAppendU32_MaxSize 10
|
||||
static constexpr int kSkStrAppendU32_MaxSize = 10;
|
||||
char* SkStrAppendU32(char buffer[], uint32_t);
|
||||
#define SkStrAppendU64_MaxSize 20
|
||||
static constexpr int kSkStrAppendU64_MaxSize = 20;
|
||||
char* SkStrAppendU64(char buffer[], uint64_t, int minDigits);
|
||||
|
||||
#define SkStrAppendS32_MaxSize (SkStrAppendU32_MaxSize + 1)
|
||||
static constexpr int kSkStrAppendS32_MaxSize = kSkStrAppendU32_MaxSize + 1;
|
||||
char* SkStrAppendS32(char buffer[], int32_t);
|
||||
#define SkStrAppendS64_MaxSize (SkStrAppendU64_MaxSize + 1)
|
||||
static constexpr int kSkStrAppendS64_MaxSize = kSkStrAppendU64_MaxSize + 1;
|
||||
char* SkStrAppendS64(char buffer[], int64_t, int minDigits);
|
||||
|
||||
/**
|
||||
@ -96,18 +96,16 @@ char* SkStrAppendS64(char buffer[], int64_t, int minDigits);
|
||||
* In theory we should only expect up to 2 digits for the exponent, but on
|
||||
* some platforms we have seen 3 (as in the example above).
|
||||
*/
|
||||
#define SkStrAppendScalar_MaxSize 15
|
||||
static constexpr int kSkStrAppendScalar_MaxSize = 15;
|
||||
|
||||
/**
|
||||
* Write the scaler in decimal format into buffer, and return a pointer to
|
||||
* Write the scalar in decimal format into buffer, and return a pointer to
|
||||
* the next char after the last one written. Note: a terminating 0 is not
|
||||
* written into buffer, which must be at least SkStrAppendScalar_MaxSize.
|
||||
* written into buffer, which must be at least kSkStrAppendScalar_MaxSize.
|
||||
* Thus if the caller wants to add a 0 at the end, buffer must be at least
|
||||
* SkStrAppendScalar_MaxSize + 1 bytes large.
|
||||
* kSkStrAppendScalar_MaxSize + 1 bytes large.
|
||||
*/
|
||||
#define SkStrAppendScalar SkStrAppendFloat
|
||||
|
||||
char* SkStrAppendFloat(char buffer[], float);
|
||||
char* SkStrAppendScalar(char buffer[], float);
|
||||
|
||||
/** \class SkString
|
||||
|
||||
|
@ -72,14 +72,14 @@ void SkWStream::flush()
|
||||
|
||||
bool SkWStream::writeDecAsText(int32_t dec)
|
||||
{
|
||||
char buffer[SkStrAppendS32_MaxSize];
|
||||
char buffer[kSkStrAppendS32_MaxSize];
|
||||
char* stop = SkStrAppendS32(buffer, dec);
|
||||
return this->write(buffer, stop - buffer);
|
||||
}
|
||||
|
||||
bool SkWStream::writeBigDecAsText(int64_t dec, int minDigits)
|
||||
{
|
||||
char buffer[SkStrAppendU64_MaxSize];
|
||||
char buffer[kSkStrAppendU64_MaxSize];
|
||||
char* stop = SkStrAppendU64(buffer, dec, minDigits);
|
||||
return this->write(buffer, stop - buffer);
|
||||
}
|
||||
@ -93,7 +93,7 @@ bool SkWStream::writeHexAsText(uint32_t hex, int digits)
|
||||
|
||||
bool SkWStream::writeScalarAsText(SkScalar value)
|
||||
{
|
||||
char buffer[SkStrAppendScalar_MaxSize];
|
||||
char buffer[kSkStrAppendScalar_MaxSize];
|
||||
char* stop = SkStrAppendScalar(buffer, value);
|
||||
return this->write(buffer, stop - buffer);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ int SkStrStartsWithOneOf(const char string[], const char prefixes[]) {
|
||||
char* SkStrAppendU32(char string[], uint32_t dec) {
|
||||
SkDEBUGCODE(char* start = string;)
|
||||
|
||||
char buffer[SkStrAppendU32_MaxSize];
|
||||
char buffer[kSkStrAppendU32_MaxSize];
|
||||
char* p = buffer + sizeof(buffer);
|
||||
|
||||
do {
|
||||
@ -102,7 +102,7 @@ char* SkStrAppendU32(char string[], uint32_t dec) {
|
||||
while (p < stop) {
|
||||
*string++ = *p++;
|
||||
}
|
||||
SkASSERT(string - start <= SkStrAppendU32_MaxSize);
|
||||
SkASSERT(string - start <= kSkStrAppendU32_MaxSize);
|
||||
return string;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ char* SkStrAppendS32(char string[], int32_t dec) {
|
||||
char* SkStrAppendU64(char string[], uint64_t dec, int minDigits) {
|
||||
SkDEBUGCODE(char* start = string;)
|
||||
|
||||
char buffer[SkStrAppendU64_MaxSize];
|
||||
char buffer[kSkStrAppendU64_MaxSize];
|
||||
char* p = buffer + sizeof(buffer);
|
||||
|
||||
do {
|
||||
@ -137,7 +137,7 @@ char* SkStrAppendU64(char string[], uint64_t dec, int minDigits) {
|
||||
memcpy(string, p, cp_len);
|
||||
string += cp_len;
|
||||
|
||||
SkASSERT(string - start <= SkStrAppendU64_MaxSize);
|
||||
SkASSERT(string - start <= kSkStrAppendU64_MaxSize);
|
||||
return string;
|
||||
}
|
||||
|
||||
@ -150,14 +150,14 @@ char* SkStrAppendS64(char string[], int64_t dec, int minDigits) {
|
||||
return SkStrAppendU64(string, udec, minDigits);
|
||||
}
|
||||
|
||||
char* SkStrAppendFloat(char string[], float value) {
|
||||
char* SkStrAppendScalar(char string[], float value) {
|
||||
// since floats have at most 8 significant digits, we limit our %g to that.
|
||||
static const char gFormat[] = "%.8g";
|
||||
// make it 1 larger for the terminating 0
|
||||
char buffer[SkStrAppendScalar_MaxSize + 1];
|
||||
char buffer[kSkStrAppendScalar_MaxSize + 1];
|
||||
int len = snprintf(buffer, sizeof(buffer), gFormat, value);
|
||||
memcpy(string, buffer, len);
|
||||
SkASSERT(len <= SkStrAppendScalar_MaxSize);
|
||||
SkASSERT(len <= kSkStrAppendScalar_MaxSize);
|
||||
return string + len;
|
||||
}
|
||||
|
||||
@ -440,25 +440,25 @@ void SkString::insertUnichar(size_t offset, SkUnichar uni) {
|
||||
}
|
||||
|
||||
void SkString::insertS32(size_t offset, int32_t dec) {
|
||||
char buffer[SkStrAppendS32_MaxSize];
|
||||
char buffer[kSkStrAppendS32_MaxSize];
|
||||
char* stop = SkStrAppendS32(buffer, dec);
|
||||
this->insert(offset, buffer, stop - buffer);
|
||||
}
|
||||
|
||||
void SkString::insertS64(size_t offset, int64_t dec, int minDigits) {
|
||||
char buffer[SkStrAppendS64_MaxSize];
|
||||
char buffer[kSkStrAppendS64_MaxSize];
|
||||
char* stop = SkStrAppendS64(buffer, dec, minDigits);
|
||||
this->insert(offset, buffer, stop - buffer);
|
||||
}
|
||||
|
||||
void SkString::insertU32(size_t offset, uint32_t dec) {
|
||||
char buffer[SkStrAppendU32_MaxSize];
|
||||
char buffer[kSkStrAppendU32_MaxSize];
|
||||
char* stop = SkStrAppendU32(buffer, dec);
|
||||
this->insert(offset, buffer, stop - buffer);
|
||||
}
|
||||
|
||||
void SkString::insertU64(size_t offset, uint64_t dec, int minDigits) {
|
||||
char buffer[SkStrAppendU64_MaxSize];
|
||||
char buffer[kSkStrAppendU64_MaxSize];
|
||||
char* stop = SkStrAppendU64(buffer, dec, minDigits);
|
||||
this->insert(offset, buffer, stop - buffer);
|
||||
}
|
||||
@ -484,7 +484,7 @@ void SkString::insertHex(size_t offset, uint32_t hex, int minDigits) {
|
||||
}
|
||||
|
||||
void SkString::insertScalar(size_t offset, SkScalar value) {
|
||||
char buffer[SkStrAppendScalar_MaxSize];
|
||||
char buffer[kSkStrAppendScalar_MaxSize];
|
||||
char* stop = SkStrAppendScalar(buffer, value);
|
||||
this->insert(offset, buffer, stop - buffer);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ static_assert(2 == (int)SkPDFResourceType::kXObject, "resource_type_mismatch")
|
||||
static_assert(3 == (int)SkPDFResourceType::kFont, "resource_type_mismatch");
|
||||
|
||||
// One extra character for the Prefix.
|
||||
constexpr size_t kMaxResourceNameLength = 1 + SkStrAppendS32_MaxSize;
|
||||
constexpr size_t kMaxResourceNameLength = 1 + kSkStrAppendS32_MaxSize;
|
||||
|
||||
// returns pointer just past end of what's written into `dst`.
|
||||
static char* get_resource_name(char dst[kMaxResourceNameLength], SkPDFResourceType type, int key) {
|
||||
|
@ -155,7 +155,7 @@ DEF_TEST(String, reporter) {
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
|
||||
a.reset();
|
||||
a.appendScalar(gRec[i].fValue);
|
||||
REPORTER_ASSERT(reporter, a.size() <= SkStrAppendScalar_MaxSize);
|
||||
REPORTER_ASSERT(reporter, a.size() <= kSkStrAppendScalar_MaxSize);
|
||||
if (!a.equals(gRec[i].fString)) {
|
||||
ERRORF(reporter, "received <%s> expected <%s>\n", a.c_str(), gRec[i].fString);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user