Skip to content

Commit b02251e

Browse files
javachefacebook-github-bot
authored andcommitted
Simplify RawValue container type checks (#53508)
Summary: Pull Request resolved: #53508 Simplify the expressions for checking a type of a container by always returning instead of falling through and returning. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D81230049 fbshipit-source-id: 02fd827462c9acf05a83bf88ed6bd0e6db55ebc8
1 parent a44c5a0 commit b02251e

File tree

1 file changed

+4
-21
lines changed
  • packages/react-native/ReactCommon/react/renderer/core

1 file changed

+4
-21
lines changed

packages/react-native/ReactCommon/react/renderer/core/RawValue.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,8 @@ class RawValue {
273273
}
274274

275275
for (const auto& item : dynamic) {
276-
if (!checkValueType(item, (T*)nullptr)) {
277-
return false;
278-
}
279-
280276
// Note: We test only one element.
281-
break;
277+
return checkValueType(item, (T*)nullptr);
282278
}
283279

284280
return true;
@@ -294,7 +290,6 @@ class RawValue {
294290
}
295291

296292
jsi::Object asObject = value.getObject(*runtime);
297-
298293
if (!asObject.isArray(*runtime)) {
299294
return false;
300295
}
@@ -303,12 +298,8 @@ class RawValue {
303298
size_t size = array.size(*runtime);
304299
for (size_t i = 0; i < size; i++) {
305300
jsi::Value itemValue = array.getValueAtIndex(*runtime, i);
306-
if (!checkValueType(runtime, itemValue, (T*)nullptr)) {
307-
return false;
308-
}
309-
310301
// Note: We test only one element.
311-
break;
302+
return checkValueType(runtime, itemValue, (T*)nullptr);
312303
}
313304

314305
return true;
@@ -324,12 +315,8 @@ class RawValue {
324315

325316
for (const auto& item : dynamic.items()) {
326317
react_native_assert(item.first.isString());
327-
if (!checkValueType(item.second, (T*)nullptr)) {
328-
return false;
329-
}
330-
331318
// Note: We test only one element.
332-
break;
319+
return checkValueType(item.second, (T*)nullptr);
333320
}
334321

335322
return true;
@@ -352,12 +339,8 @@ class RawValue {
352339
jsi::String propertyName =
353340
propertyNames.getValueAtIndex(*runtime, i).getString(*runtime);
354341
jsi::Value propertyValue = asObject.getProperty(*runtime, propertyName);
355-
if (!checkValueType(runtime, propertyValue, (T*)nullptr)) {
356-
return false;
357-
}
358-
359342
// Note: We test only one element.
360-
break;
343+
return checkValueType(runtime, propertyValue, (T*)nullptr);
361344
}
362345

363346
return true;

0 commit comments

Comments
 (0)