Skip to content

Commit 4f48cee

Browse files
committed
Use 'ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY' instead of comparison with 'sizeof'
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
1 parent df1e428 commit 4f48cee

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

jerry-core/ecma/base/ecma-helpers-external-pointers.c

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,29 @@ ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to crea
6464
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (ECMA_PROPERTY_VALUE_PTR (prop_p)->value),
6565
size_of_internal_property_value_must_be_greater_than_or_equal_to_4_bytes);
6666

67-
if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
67+
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
68+
69+
ECMA_PROPERTY_VALUE_PTR (prop_p)->value = (ecma_value_t) ptr_value;
70+
71+
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
72+
73+
ecma_external_pointer_t *handler_p;
74+
75+
if (is_new)
6876
{
69-
ECMA_PROPERTY_VALUE_PTR (prop_p)->value = (uint32_t) ptr_value;
77+
handler_p = ecma_alloc_external_pointer ();
78+
79+
ECMA_SET_NON_NULL_POINTER (ECMA_PROPERTY_VALUE_PTR (prop_p)->value, handler_p);
7080
}
7181
else
7282
{
73-
ecma_external_pointer_t *handler_p;
74-
75-
if (is_new)
76-
{
77-
handler_p = ecma_alloc_external_pointer ();
83+
handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
84+
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
85+
}
7886

79-
ECMA_SET_NON_NULL_POINTER (ECMA_PROPERTY_VALUE_PTR (prop_p)->value, handler_p);
80-
}
81-
else
82-
{
83-
handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
84-
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
85-
}
87+
*handler_p = ptr_value;
8688

87-
*handler_p = ptr_value;
88-
}
89+
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
8990

9091
return is_new;
9192
} /* ecma_create_external_pointer_property */
@@ -121,16 +122,17 @@ ecma_get_external_pointer_value (ecma_object_t *obj_p, /**< object to get proper
121122
return false;
122123
}
123124

124-
if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
125-
{
126-
*out_pointer_p = ECMA_PROPERTY_VALUE_PTR (prop_p)->value;
127-
}
128-
else
129-
{
130-
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
131-
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
132-
*out_pointer_p = *handler_p;
133-
}
125+
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
126+
127+
*out_pointer_p = ECMA_PROPERTY_VALUE_PTR (prop_p)->value;
128+
129+
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
130+
131+
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
132+
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
133+
*out_pointer_p = *handler_p;
134+
135+
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
134136

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

154-
if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
155-
{
156-
/* no additional memory was allocated for the pointer storage */
157-
}
158-
else
159-
{
160-
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
161-
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
156+
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
157+
158+
/* no additional memory was allocated for the pointer storage */
159+
160+
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
161+
162+
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
163+
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
164+
165+
ecma_dealloc_external_pointer (handler_p);
166+
167+
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
162168

163-
ecma_dealloc_external_pointer (handler_p);
164-
}
165169
} /* ecma_free_external_pointer_in_property */
166170

167171
/**

0 commit comments

Comments
 (0)