Skip to content

Commit 6361ae5

Browse files
authored
Reduce size of Method::parse_types
Differential Revision: D68037113 Pull Request resolved: #7603
1 parent 36e4782 commit 6361ae5

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

runtime/executor/method.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ Error Method::parse_values() {
313313
"Null value at index %zu",
314314
i);
315315

316+
const auto val = serialization_value->val();
317+
316318
switch (serialization_value->val_type()) {
317319
case executorch_flatbuffer::KernelTypes::Null: {
318320
// Placement new as the list elements are not initialized, so calling
@@ -321,18 +323,21 @@ Error Method::parse_values() {
321323
new (&values_[i]) EValue();
322324
} break;
323325
case executorch_flatbuffer::KernelTypes::Int: {
324-
new (&values_[i]) EValue(serialization_value->val_as_Int()->int_val());
326+
new (&values_[i]) EValue(
327+
static_cast<const executorch_flatbuffer::Int*>(val)->int_val());
325328
} break;
326329
case executorch_flatbuffer::KernelTypes::Double: {
327330
new (&values_[i])
328-
EValue(serialization_value->val_as_Double()->double_val());
331+
EValue(static_cast<const executorch_flatbuffer::Double*>(val)
332+
->double_val());
329333
} break;
330334
case executorch_flatbuffer::KernelTypes::Bool: {
331-
new (&values_[i])
332-
EValue(serialization_value->val_as_Bool()->bool_val());
335+
new (&values_[i]) EValue(
336+
static_cast<const executorch_flatbuffer::Bool*>(val)->bool_val());
333337
} break;
334338
case executorch_flatbuffer::KernelTypes::IntList: {
335-
const auto items = serialization_value->val_as_IntList()->items();
339+
const auto items =
340+
static_cast<const executorch_flatbuffer::IntList*>(val)->items();
336341
ET_CHECK_OR_RETURN_ERROR(
337342
items != nullptr, InvalidProgram, "Missing list at index %zu", i);
338343
// Allocate space for boxed and unboxed list representations using
@@ -352,7 +357,8 @@ Error Method::parse_values() {
352357
BoxedEvalueList<int64_t>(evalp_list, int_list, items->size()));
353358
} break;
354359
case executorch_flatbuffer::KernelTypes::BoolList: {
355-
const auto items = serialization_value->val_as_BoolList()->items();
360+
const auto items =
361+
static_cast<const executorch_flatbuffer::BoolList*>(val)->items();
356362
ET_CHECK_OR_RETURN_ERROR(
357363
items != nullptr, InvalidProgram, "Missing list at index %zu", i);
358364
// NOTE: This is technically not portable. A platform could technically
@@ -366,14 +372,17 @@ Error Method::parse_values() {
366372
(const bool*)items->data(), items->size()));
367373
} break;
368374
case executorch_flatbuffer::KernelTypes::DoubleList: {
369-
const auto items = serialization_value->val_as_DoubleList()->items();
375+
const auto items =
376+
static_cast<const executorch_flatbuffer::DoubleList*>(val)->items();
370377
ET_CHECK_OR_RETURN_ERROR(
371378
items != nullptr, InvalidProgram, "Missing list at index %zu", i);
372379
new (&values_[i])
373380
EValue(exec_aten::ArrayRef<double>(items->data(), items->size()));
374381
} break;
375382
case executorch_flatbuffer::KernelTypes::String: {
376-
const auto fb_str = serialization_value->val_as_String()->string_val();
383+
const auto fb_str =
384+
static_cast<const executorch_flatbuffer::String*>(val)
385+
->string_val();
377386
ET_CHECK_OR_RETURN_ERROR(
378387
fb_str != nullptr,
379388
InvalidProgram,
@@ -383,7 +392,9 @@ Error Method::parse_values() {
383392
} break;
384393
case executorch_flatbuffer::KernelTypes::Tensor: {
385394
auto t = deserialization::parseTensor(
386-
program_, memory_manager_, serialization_value->val_as_Tensor());
395+
program_,
396+
memory_manager_,
397+
static_cast<const executorch_flatbuffer::Tensor*>(val));
387398
if (!t.ok()) {
388399
ET_LOG(
389400
Error,
@@ -398,7 +409,7 @@ Error Method::parse_values() {
398409
// get list of serialization tensors and allocate storage for executor
399410
// tensors
400411
auto tensors = deserialization::parseTensorList(
401-
serialization_value->val_as_TensorList()->items(),
412+
static_cast<const executorch_flatbuffer::TensorList*>(val)->items(),
402413
values_,
403414
memory_manager_);
404415
if (!tensors.ok()) {
@@ -415,7 +426,9 @@ Error Method::parse_values() {
415426
// Same as TensorList but optional<Tensor> instead of Tensor
416427
auto tensors =
417428
deserialization::parseListOptionalType<exec_aten::Tensor>(
418-
serialization_value->val_as_OptionalTensorList()->items(),
429+
static_cast<const executorch_flatbuffer::OptionalTensorList*>(
430+
val)
431+
->items(),
419432
values_,
420433
memory_manager_);
421434
if (!tensors.ok()) {

0 commit comments

Comments
 (0)