Don't pass std::string by pointer

Summary:
@public

Pass strings by mutable ref rather than pointer.

Reviewed By: SidharthGuglani

Differential Revision: D13439613

fbshipit-source-id: ea889abe0fe8ec44ae02f13c1d9a10c0dbfdbcf1
This commit is contained in:
David Aurelio
2018-12-13 07:09:31 -08:00
committed by Facebook Github Bot
parent dd97fcc968
commit 130a9a2aa2
3 changed files with 15 additions and 16 deletions

View File

@@ -14,9 +14,9 @@ namespace facebook {
namespace yoga { namespace yoga {
typedef std::string string; typedef std::string string;
static void indent(string* base, uint32_t level) { static void indent(string& base, uint32_t level) {
for (uint32_t i = 0; i < level; ++i) { for (uint32_t i = 0; i < level; ++i) {
base->append(" "); base.append(" ");
} }
} }
@@ -25,7 +25,7 @@ static bool areFourValuesEqual(const std::array<YGValue, YGEdgeCount>& four) {
YGValueEqual(four[0], four[3]); YGValueEqual(four[0], four[3]);
} }
static void appendFormatedString(string* str, const char* fmt, ...) { static void appendFormatedString(string& str, const char* fmt, ...) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
va_list argsCopy; va_list argsCopy;
@@ -35,11 +35,11 @@ static void appendFormatedString(string* str, const char* fmt, ...) {
vsnprintf(buf.data(), buf.size(), fmt, argsCopy); vsnprintf(buf.data(), buf.size(), fmt, argsCopy);
va_end(argsCopy); va_end(argsCopy);
string result = string(buf.begin(), buf.end() - 1); string result = string(buf.begin(), buf.end() - 1);
str->append(result); str.append(result);
} }
static void appendFloatOptionalIfDefined( static void appendFloatOptionalIfDefined(
string* base, string& base,
const string key, const string key,
const YGFloatOptional num) { const YGFloatOptional num) {
if (!num.isUndefined()) { if (!num.isUndefined()) {
@@ -48,12 +48,12 @@ static void appendFloatOptionalIfDefined(
} }
static void appendNumberIfNotUndefined( static void appendNumberIfNotUndefined(
string* base, string& base,
const string key, const string key,
const YGValue number) { const YGValue number) {
if (number.unit != YGUnitUndefined) { if (number.unit != YGUnitUndefined) {
if (number.unit == YGUnitAuto) { if (number.unit == YGUnitAuto) {
base->append(key + ": auto; "); base.append(key + ": auto; ");
} else { } else {
string unit = number.unit == YGUnitPoint ? "px" : "%%"; string unit = number.unit == YGUnitPoint ? "px" : "%%";
appendFormatedString( appendFormatedString(
@@ -63,24 +63,23 @@ static void appendNumberIfNotUndefined(
} }
static void static void
appendNumberIfNotAuto(string* base, const string& key, const YGValue number) { appendNumberIfNotAuto(string& base, const string& key, const YGValue number) {
if (number.unit != YGUnitAuto) { if (number.unit != YGUnitAuto) {
appendNumberIfNotUndefined(base, key, number); appendNumberIfNotUndefined(base, key, number);
} }
} }
static void static void
appendNumberIfNotZero(string* base, const string& str, const YGValue number) { appendNumberIfNotZero(string& base, const string& str, const YGValue number) {
if (number.unit == YGUnitAuto) { if (number.unit == YGUnitAuto) {
base->append(str + ": auto; "); base.append(str + ": auto; ");
} else if (!YGFloatsEqual(number.value, 0)) { } else if (!YGFloatsEqual(number.value, 0)) {
appendNumberIfNotUndefined(base, str, number); appendNumberIfNotUndefined(base, str, number);
} }
} }
static void appendEdges( static void appendEdges(
string* base, string& base,
const string& key, const string& key,
const std::array<YGValue, YGEdgeCount>& edges) { const std::array<YGValue, YGEdgeCount>& edges) {
if (areFourValuesEqual(edges)) { if (areFourValuesEqual(edges)) {
@@ -94,7 +93,7 @@ static void appendEdges(
} }
static void appendEdgeIfNotUndefined( static void appendEdgeIfNotUndefined(
string* base, string& base,
const string& str, const string& str,
const std::array<YGValue, YGEdgeCount>& edges, const std::array<YGValue, YGEdgeCount>& edges,
const YGEdge edge) { const YGEdge edge) {
@@ -103,7 +102,7 @@ static void appendEdgeIfNotUndefined(
} }
void YGNodeToString( void YGNodeToString(
std::string* str, std::string& str,
YGNodeRef node, YGNodeRef node,
YGPrintOptions options, YGPrintOptions options,
uint32_t level) { uint32_t level) {

View File

@@ -13,7 +13,7 @@ namespace facebook {
namespace yoga { namespace yoga {
void YGNodeToString( void YGNodeToString(
std::string* str, std::string& str,
YGNodeRef node, YGNodeRef node,
YGPrintOptions options, YGPrintOptions options,
uint32_t level); uint32_t level);

View File

@@ -1060,7 +1060,7 @@ static void YGNodePrintInternal(
const YGNodeRef node, const YGNodeRef node,
const YGPrintOptions options) { const YGPrintOptions options) {
std::string str; std::string str;
facebook::yoga::YGNodeToString(&str, node, options, 0); facebook::yoga::YGNodeToString(str, node, options, 0);
YGLog(node, YGLogLevelDebug, str.c_str()); YGLog(node, YGLogLevelDebug, str.c_str());
} }