Skip to content

Commit 5ef4594

Browse files
committed
Phase 120: Complete boolean return type conversions
Converted 4 remaining predicate functions from int to bool: - iscleared() (gc_weak.cpp:52) - GC weak table predicate - isneg() (lobject.cpp:207) - Sign checking predicate - rawfinishnodeset() (ltable.cpp:1187) - Table insertion success check - checkbuffer() (lzio.cpp:46) - Buffer validation predicate Also updated call site in Table::setInt() to use bool variable. This completes the boolean modernization initiative started in Phases 113 and 117, bringing total bool conversions to 16 functions. Testing: - All tests pass (final OK !!!) - Performance: 4.45s avg (within acceptable bounds) Follows pattern from Phase 117 (5 predicates) and Phase 113 (7 predicates).
1 parent 5d1ca7c commit 5ef4594

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/memory/gc/gc_weak.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
** For other objects: if really collected, cannot keep them; for objects
5050
** being finalized, keep them in keys, but not in values.
5151
*/
52-
static int iscleared(global_State* g, const GCObject* o) {
53-
if (o == nullptr) return 0; /* non-collectable value */
52+
static bool iscleared(global_State* g, const GCObject* o) {
53+
if (o == nullptr) return false; /* non-collectable value */
5454
else if (novariant(o->getType()) == LUA_TSTRING) {
5555
markobject(g, o); /* strings are 'values', so are never weak */
56-
return 0;
56+
return false;
5757
}
5858
else return iswhite(o);
5959
}

src/objects/lobject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ lu_byte luaO_hexavalue (int c) {
204204
}
205205

206206

207-
static int isneg (const char **s) {
208-
if (**s == '-') { (*s)++; return 1; }
207+
static bool isneg (const char **s) {
208+
if (**s == '-') { (*s)++; return true; }
209209
else if (**s == '+') (*s)++;
210-
return 0;
210+
return false;
211211
}
212212

213213

src/objects/ltable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,12 +1184,12 @@ static int finishnodeset (Table *t, TValue *slot, TValue *val) {
11841184
}
11851185

11861186

1187-
static int rawfinishnodeset (TValue *slot, TValue *val) {
1187+
static bool rawfinishnodeset (TValue *slot, TValue *val) {
11881188
if (isabstkey(slot))
1189-
return 0; /* no slot with that key */
1189+
return false; /* no slot with that key */
11901190
else {
11911191
*slot = *val;
1192-
return 1; /* success */
1192+
return true; /* success */
11931193
}
11941194
}
11951195

@@ -1522,7 +1522,7 @@ void Table::setInt(lua_State* L, lua_Integer key, TValue* value) {
15221522
if (ik > 0)
15231523
obj2arr(this, ik - 1, value);
15241524
else {
1525-
int ok = rawfinishnodeset(getintfromhash(this, key), value);
1525+
bool ok = rawfinishnodeset(getintfromhash(this, key), value);
15261526
if (!ok) {
15271527
TValue k;
15281528
setivalue(&k, key);

src/serialization/lzio.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
4343

4444
/* --------------------------------------------------------------- read --- */
4545

46-
static int checkbuffer (ZIO *z) {
46+
static bool checkbuffer (ZIO *z) {
4747
if (z->n == 0) { /* no bytes in buffer? */
4848
if (luaZ_fill(z) == EOZ) /* try to read more */
49-
return 0; /* no more input */
49+
return false; /* no more input */
5050
else {
5151
z->n++; /* luaZ_fill consumed first byte; put it back */
5252
z->p--;
5353
}
5454
}
55-
return 1; /* now buffer has something */
55+
return true; /* now buffer has something */
5656
}
5757

5858

0 commit comments

Comments
 (0)