Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-promise-object.c (C)

Code before:
    /* 8. */
    ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values),
                                 (uint32_t) (executor_p->index - 1),
                                 args_p[0],
                                 false);
  }
  else
  {
    ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
    ecma_object_t *obj_p = ecma_create_object (object_prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL);
    ecma_property_value_t *prop_value_p;
    prop_value_p = ecma_create_named_data_property (obj_p,
                                                    ecma_get_magic_string (LIT_MAGIC_STRING_STATUS),
                                                    ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
                                                    NULL);

    if (promise_type == ECMA_PROMISE_ALLSETTLED_RESOLVE)
    {
      prop_value_p->value = ecma_make_magic_string_value (LIT_MAGIC_STRING_FULFILLED);
    }
    else
    {
      prop_value_p->value = ecma_make_magic_string_value (LIT_MAGIC_STRING_REJECTED);
    }

    if (promise_type == ECMA_PROMISE_ALLSETTLED_RESOLVE)
    {
      prop_value_p = ecma_create_named_data_property (obj_p,
                                                      ecma_get_magic_string (LIT_MAGIC_STRING_VALUE),
                                                      ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
                                                      NULL);
    }
    else
    {
      prop_value_p = ecma_create_named_data_property (obj_p,
                                                ecma_get_magic_string (LIT_MAGIC_STRING_REASON),
                                                ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
                                                NULL);
    }

    prop_value_p->value = args_p[0];

    ecma_value_t obj_val = ecma_make_object_value (obj_p);
    /* 12. */
    ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values),
                                 (uint32_t) (executor_p->index - 1),
                                 obj_val,
                                 false);
  }
  /* 3. */
  executor_p->index = 0;

Review comment (suggestion):
I would create a local string (name_p), where the `ecma_get_magic_string (LIT_MAGIC_STRING_VALUE)` or `ecma_get_magic_string (LIT_MAGIC_STRING_REASON)` is stored, and call ecma_create_named_data_property only once.

Code after:
    /* 8. */
    ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values),
                                 (uint32_t) (executor_p->index - 1),
                                 args_p[0],
                                 false);
  }
  else
  {
    lit_magic_string_id_t status_property_val = LIT_MAGIC_STRING_REJECTED;
    lit_magic_string_id_t data_propery_name = LIT_MAGIC_STRING_REASON;

    if (promise_type == ECMA_PROMISE_ALLSETTLED_RESOLVE)
    {
      status_property_val =  LIT_MAGIC_STRING_FULFILLED;
      data_propery_name = LIT_MAGIC_STRING_VALUE;
    }

    ecma_object_t *obj_p = ecma_create_object (NULL, 0, ECMA_OBJECT_TYPE_GENERAL);
    ecma_property_value_t *prop_value_p;
    prop_value_p = ecma_create_named_data_property (obj_p,
                                                    ecma_get_magic_string (LIT_MAGIC_STRING_STATUS),
                                                    ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
                                                    NULL);

    prop_value_p->value = ecma_make_magic_string_value (status_property_val);

    prop_value_p = ecma_create_named_data_property (obj_p,
                                                    ecma_get_magic_string (data_propery_name),
                                                    ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
                                                    NULL);
    prop_value_p->value = ECMA_VALUE_UNDEFINED;

    if (args_count != 0)
    {
      prop_value_p->value = ecma_copy_value_if_not_object (args_p[0]);
    }

    ecma_value_t obj_val = ecma_make_object_value (obj_p);
    /* 12. */
    ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values),
                                (uint32_t) (executor_p->index - 1),
                                 obj_val,
                                 false);
    ecma_deref_object (obj_p);
  }
  /* 3. */
  executor_p->index = 0;

  /* 9-10. */
  ecma_value_t ret = ECMA_VALUE_UNDEFINED;
  if (ecma_promise_remaining_inc_or_dec (executor_p->remaining_elements, false) == 0)