Skip to content

Commit

Permalink
Don't pass std::string by pointer
Browse files Browse the repository at this point in the history
Summary:
@public

Pass strings by mutable ref rather than pointer.

Reviewed By: SidharthGuglani

Differential Revision: D13236159

fbshipit-source-id: 04fd35e8a9e106ba8cdd71cfab31e8d90edaac9e
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Dec 6, 2018
1 parent 4248fd9 commit 6b7f698
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions yoga/YGNodePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace facebook {
namespace yoga {
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) {
base->append(" ");
base.append(" ");
}
}

Expand All @@ -25,7 +25,7 @@ static bool areFourValuesEqual(const std::array<YGValue, YGEdgeCount>& four) {
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_start(args, fmt);
va_list argsCopy;
Expand All @@ -35,11 +35,11 @@ static void appendFormatedString(string* str, const char* fmt, ...) {
vsnprintf(buf.data(), buf.size(), fmt, argsCopy);
va_end(argsCopy);
string result = string(buf.begin(), buf.end() - 1);
str->append(result);
str.append(result);
}

static void appendFloatOptionalIfDefined(
string* base,
string& base,
const string key,
const YGFloatOptional num) {
if (!num.isUndefined()) {
Expand All @@ -48,12 +48,12 @@ static void appendFloatOptionalIfDefined(
}

static void appendNumberIfNotUndefined(
string* base,
string& base,
const string key,
const YGValue number) {
if (number.unit != YGUnitUndefined) {
if (number.unit == YGUnitAuto) {
base->append(key + ": auto; ");
base.append(key + ": auto; ");
} else {
string unit = number.unit == YGUnitPoint ? "px" : "%%";
appendFormatedString(
Expand All @@ -63,23 +63,23 @@ static void appendNumberIfNotUndefined(
}

static void
appendNumberIfNotAuto(string* base, const string& key, const YGValue number) {
appendNumberIfNotAuto(string& base, const string& key, const YGValue number) {
if (number.unit != YGUnitAuto) {
appendNumberIfNotUndefined(base, key, number);
}
}

static void
appendNumberIfNotZero(string* base, const string& str, const YGValue number) {
appendNumberIfNotZero(string& base, const string& str, const YGValue number) {
if (number.unit == YGUnitAuto) {
base->append(str + ": auto; ");
base.append(str + ": auto; ");
} else if (!YGFloatsEqual(number.value, 0)) {
appendNumberIfNotUndefined(base, str, number);
}
}

static void appendEdges(
string* base,
string& base,
const string& key,
const std::array<YGValue, YGEdgeCount>& edges) {
if (areFourValuesEqual(edges)) {
Expand All @@ -93,7 +93,7 @@ static void appendEdges(
}

static void appendEdgeIfNotUndefined(
string* base,
string& base,
const string& str,
const std::array<YGValue, YGEdgeCount>& edges,
const YGEdge edge) {
Expand All @@ -102,7 +102,7 @@ static void appendEdgeIfNotUndefined(
}

void YGNodeToString(
std::string* str,
std::string& str,
YGNodeRef node,
YGPrintOptions options,
uint32_t level) {
Expand Down
2 changes: 1 addition & 1 deletion yoga/YGNodePrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace facebook {
namespace yoga {

void YGNodeToString(
std::string* str,
std::string& str,
YGNodeRef node,
YGPrintOptions options,
uint32_t level);
Expand Down
2 changes: 1 addition & 1 deletion yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ static void YGNodePrintInternal(
const YGNodeRef node,
const YGPrintOptions options) {
std::string str;
facebook::yoga::YGNodeToString(&str, node, options, 0);
facebook::yoga::YGNodeToString(str, node, options, 0);
YGLog(node, YGLogLevelDebug, str.c_str());
}

Expand Down

0 comments on commit 6b7f698

Please sign in to comment.