Skip to content

Commit c8e7f2d

Browse files
committed
Add true and false global string constants
1 parent 4db9965 commit c8e7f2d

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/scratch/value_functions.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ extern "C"
281281
else if (v->type == ValueType::Bool) {
282282
if (v->boolValue) {
283283
StringPtr *ret = string_pool_new();
284-
string_assign_cstring(ret, "true");
284+
string_assign(ret, &TRUE_STR);
285285
return ret;
286286
} else {
287287
StringPtr *ret = string_pool_new();
288-
string_assign_cstring(ret, "false");
288+
string_assign(ret, &FALSE_STR);
289289
return ret;
290290
}
291291
} else
@@ -453,13 +453,7 @@ extern "C"
453453
*/
454454
const StringPtr *value_boolToStringPtr(bool v)
455455
{
456-
if (v) {
457-
static const StringPtr ret("true");
458-
return &ret;
459-
} else {
460-
static const StringPtr ret("false");
461-
return &ret;
462-
}
456+
return v ? &TRUE_STR : &FALSE_STR;
463457
}
464458

465459
/*! Converts the given string to double. */

src/scratch/value_functions_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
namespace libscratchcpp
2222
{
2323

24+
static const StringPtr TRUE_STR("true");
25+
static const StringPtr FALSE_STR("false");
26+
2427
template<typename T>
2528
inline unsigned int value_intDigitCount(T v)
2629
{

0 commit comments

Comments
 (0)