Skip to content

Use 'ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY' instead of comparis… #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions jerry-core/ecma/base/ecma-helpers-external-pointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,29 @@ ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to crea
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (ECMA_PROPERTY_VALUE_PTR (prop_p)->value),
size_of_internal_property_value_must_be_greater_than_or_equal_to_4_bytes);

if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY

ECMA_PROPERTY_VALUE_PTR (prop_p)->value = (ecma_value_t) ptr_value;

#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */

ecma_external_pointer_t *handler_p;

if (is_new)
{
ECMA_PROPERTY_VALUE_PTR (prop_p)->value = (uint32_t) ptr_value;
handler_p = ecma_alloc_external_pointer ();

ECMA_SET_NON_NULL_POINTER (ECMA_PROPERTY_VALUE_PTR (prop_p)->value, handler_p);
}
else
{
ecma_external_pointer_t *handler_p;

if (is_new)
{
handler_p = ecma_alloc_external_pointer ();
handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
}

ECMA_SET_NON_NULL_POINTER (ECMA_PROPERTY_VALUE_PTR (prop_p)->value, handler_p);
}
else
{
handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
}
*handler_p = ptr_value;

*handler_p = ptr_value;
}
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */

return is_new;
} /* ecma_create_external_pointer_property */
Expand Down Expand Up @@ -121,16 +122,17 @@ ecma_get_external_pointer_value (ecma_object_t *obj_p, /**< object to get proper
return false;
}

if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
{
*out_pointer_p = ECMA_PROPERTY_VALUE_PTR (prop_p)->value;
}
else
{
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
*out_pointer_p = *handler_p;
}
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY

*out_pointer_p = ECMA_PROPERTY_VALUE_PTR (prop_p)->value;

#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */

ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
*out_pointer_p = *handler_p;

#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */

return true;
} /* ecma_get_external_pointer_value */
Expand All @@ -151,17 +153,19 @@ ecma_free_external_pointer_in_property (ecma_property_t *prop_p) /**< internal p
|| ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
|| ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);

if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
{
/* no additional memory was allocated for the pointer storage */
}
else
{
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this comment


/* no additional memory was allocated for the pointer storage */

#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */

ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);

ecma_dealloc_external_pointer (handler_p);

#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've updated this comment.


ecma_dealloc_external_pointer (handler_p);
}
} /* ecma_free_external_pointer_in_property */

/**
Expand Down