Introducing ECMA_GET_NON_NULL_POINTER macro that is ECMA_GET_POINTER without NULL pointer check.

Replacing invocations of ECMA_GET_POINTER passing non-NULL argument with introduced ECMA_GET_NON_NULL_POINTER.
This commit is contained in:
Ruben Ayrapetyan
2014-11-13 19:09:13 +03:00
parent 0e10e97120
commit 477a694622
39 changed files with 190 additions and 183 deletions
+4 -4
View File
@@ -243,7 +243,7 @@ ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, /**<
return;
}
ecma_object_t *ref_obj_p = ECMA_GET_POINTER(value.value);
ecma_object_t *ref_obj_p = ECMA_GET_NON_NULL_POINTER(value.value);
JERRY_ASSERT(ref_obj_p != NULL);
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, ref_obj_p);
@@ -323,7 +323,7 @@ ecma_gc_mark (ecma_object_t *object_p, /**< start object */
property_p != NULL;
property_p = next_property_p)
{
next_property_p = ECMA_GET_POINTER(property_p->next_property_p);
next_property_p = ECMA_GET_NON_NULL_POINTER(property_p->next_property_p);
switch ((ecma_property_type_t) property_p->type)
{
@@ -333,7 +333,7 @@ ecma_gc_mark (ecma_object_t *object_p, /**< start object */
if (value.value_type == ECMA_TYPE_OBJECT)
{
ecma_object_t *value_obj_p = ECMA_GET_POINTER(value.value);
ecma_object_t *value_obj_p = ECMA_GET_NON_NULL_POINTER(value.value);
if (ecma_gc_get_object_generation (value_obj_p) <= maximum_gen_to_traverse)
{
@@ -423,7 +423,7 @@ ecma_gc_mark (ecma_object_t *object_p, /**< start object */
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */
{
ecma_object_t *obj_p = ECMA_GET_POINTER(property_value);
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER(property_value);
if (ecma_gc_get_object_generation (obj_p) <= maximum_gen_to_traverse)
{
+20 -20
View File
@@ -309,8 +309,8 @@ ecma_copy_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
case ECMA_STRING_CONTAINER_CONCATENATION:
{
ecma_string_t *part1_p = ECMA_GET_POINTER (string_desc_p->u.concatenation.string1_cp);
ecma_string_t *part2_p = ECMA_GET_POINTER (string_desc_p->u.concatenation.string2_cp);
ecma_string_t *part1_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.concatenation.string1_cp);
ecma_string_t *part2_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.concatenation.string2_cp);
new_str_p = ecma_concat_ecma_strings (part1_p, part2_p);
@@ -319,7 +319,7 @@ ecma_copy_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
{
ecma_number_t *num_p = ECMA_GET_POINTER (string_desc_p->u.number_cp);
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.number_cp);
new_str_p = ecma_new_ecma_string_from_number (*num_p);
@@ -328,7 +328,7 @@ ecma_copy_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
case ECMA_STRING_CONTAINER_HEAP_CHUNKS:
{
ecma_collection_chunk_t *str_heap_chunk_p = ECMA_GET_POINTER (string_desc_p->u.chunk_cp);
ecma_collection_chunk_t *str_heap_chunk_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.chunk_cp);
JERRY_ASSERT (str_heap_chunk_p != NULL);
new_str_p = ecma_alloc_string ();
@@ -432,7 +432,7 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
{
case ECMA_STRING_CONTAINER_HEAP_CHUNKS:
{
ecma_collection_chunk_t *chunk_p = ECMA_GET_POINTER (string_p->u.chunk_cp);
ecma_collection_chunk_t *chunk_p = ECMA_GET_NON_NULL_POINTER (string_p->u.chunk_cp);
JERRY_ASSERT (chunk_p != NULL);
@@ -449,7 +449,7 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
}
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
{
ecma_number_t *num_p = ECMA_GET_POINTER (string_p->u.number_cp);
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER (string_p->u.number_cp);
ecma_dealloc_number (num_p);
@@ -459,8 +459,8 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
{
ecma_string_t *string1_p, *string2_p;
string1_p = ECMA_GET_POINTER (string_p->u.concatenation.string1_cp);
string2_p = ECMA_GET_POINTER (string_p->u.concatenation.string2_cp);
string1_p = ECMA_GET_NON_NULL_POINTER (string_p->u.concatenation.string1_cp);
string2_p = ECMA_GET_NON_NULL_POINTER (string_p->u.concatenation.string2_cp);
ecma_deref_ecma_string (string1_p);
ecma_deref_ecma_string (string2_p);
@@ -498,7 +498,7 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
{
ecma_number_t *num_p = ECMA_GET_POINTER (str_p->u.number_cp);
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER (str_p->u.number_cp);
return *num_p;
}
@@ -590,7 +590,7 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d
{
ecma_length_t string_length = string_desc_p->length;
ecma_collection_chunk_t *string_chunk_p = ECMA_GET_POINTER (string_desc_p->u.chunk_cp);
ecma_collection_chunk_t *string_chunk_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.chunk_cp);
const ecma_length_t max_chars_in_chunk = sizeof (string_chunk_p->data) / sizeof (ecma_char_t);
@@ -634,7 +634,7 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d
}
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
{
ecma_number_t *num_p = ECMA_GET_POINTER (string_desc_p->u.number_cp);
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.number_cp);
ecma_length_t length = ecma_number_to_zt_string (*num_p, buffer_p, buffer_size);
@@ -646,8 +646,8 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d
}
case ECMA_STRING_CONTAINER_CONCATENATION:
{
const ecma_string_t *string1_p = ECMA_GET_POINTER (string_desc_p->u.concatenation.string1_cp);
const ecma_string_t *string2_p = ECMA_GET_POINTER (string_desc_p->u.concatenation.string2_cp);
const ecma_string_t *string1_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.concatenation.string1_cp);
const ecma_string_t *string2_p = ECMA_GET_NON_NULL_POINTER (string_desc_p->u.concatenation.string2_cp);
ecma_char_t *dest_p = buffer_p;
@@ -703,8 +703,8 @@ ecma_compare_strings_in_heap_chunks (const ecma_string_t *string1_p, /* ecma-str
&& string2_p->container == ECMA_STRING_CONTAINER_HEAP_CHUNKS);
JERRY_ASSERT (ecma_string_get_length (string1_p) == ecma_string_get_length (string2_p));
ecma_collection_chunk_t *string1_chunk_p = ECMA_GET_POINTER (string1_p->u.chunk_cp);
ecma_collection_chunk_t *string2_chunk_p = ECMA_GET_POINTER (string2_p->u.chunk_cp);
ecma_collection_chunk_t *string1_chunk_p = ECMA_GET_NON_NULL_POINTER (string1_p->u.chunk_cp);
ecma_collection_chunk_t *string2_chunk_p = ECMA_GET_NON_NULL_POINTER (string2_p->u.chunk_cp);
ecma_length_t chars_left = string1_p->length;
const ecma_length_t max_chars_in_chunk = sizeof (string1_chunk_p->data) / sizeof (ecma_char_t);
@@ -744,7 +744,7 @@ ecma_compare_ecma_string_to_zt_string (const ecma_string_t *string_p, /**< ecma-
{
JERRY_ASSERT (string_p->container == ECMA_STRING_CONTAINER_HEAP_CHUNKS);
ecma_collection_chunk_t *string_chunk_p = ECMA_GET_POINTER (string_p->u.chunk_cp);
ecma_collection_chunk_t *string_chunk_p = ECMA_GET_NON_NULL_POINTER (string_p->u.chunk_cp);
ecma_length_t chars_left = string_p->length;
const ecma_length_t max_chars_in_chunk = sizeof (string_chunk_p->data) / sizeof (ecma_char_t);
@@ -935,8 +935,8 @@ ecma_compare_ecma_strings (const ecma_string_t *string1_p, /* ecma-string */
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
{
ecma_number_t *num1_p, *num2_p;
num1_p = ECMA_GET_POINTER (string1_p->u.number_cp);
num2_p = ECMA_GET_POINTER (string2_p->u.number_cp);
num1_p = ECMA_GET_NON_NULL_POINTER (string1_p->u.number_cp);
num2_p = ECMA_GET_NON_NULL_POINTER (string2_p->u.number_cp);
if (ecma_number_is_nan (*num1_p)
&& ecma_number_is_nan (*num2_p))
@@ -1115,8 +1115,8 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
{
const ecma_string_t *string1_p, *string2_p;
string1_p = ECMA_GET_POINTER (string_p->u.concatenation.string1_cp);
string2_p = ECMA_GET_POINTER (string_p->u.concatenation.string2_cp);
string1_p = ECMA_GET_NON_NULL_POINTER (string_p->u.concatenation.string1_cp);
string2_p = ECMA_GET_NON_NULL_POINTER (string_p->u.concatenation.string2_cp);
return ecma_string_get_length (string1_p) + ecma_string_get_length (string2_p);
}
+7 -7
View File
@@ -193,7 +193,7 @@ ecma_copy_value (const ecma_value_t value, /**< ecma-value */
}
case ECMA_TYPE_NUMBER:
{
ecma_number_t *num_p = ECMA_GET_POINTER(value.value);
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER(value.value);
JERRY_ASSERT(num_p != NULL);
ecma_number_t *number_copy_p = ecma_alloc_number ();
@@ -209,7 +209,7 @@ ecma_copy_value (const ecma_value_t value, /**< ecma-value */
}
case ECMA_TYPE_STRING:
{
ecma_string_t *string_p = ECMA_GET_POINTER(value.value);
ecma_string_t *string_p = ECMA_GET_NON_NULL_POINTER(value.value);
JERRY_ASSERT(string_p != NULL);
string_p = ecma_copy_or_ref_ecma_string (string_p);
@@ -224,7 +224,7 @@ ecma_copy_value (const ecma_value_t value, /**< ecma-value */
}
case ECMA_TYPE_OBJECT:
{
ecma_object_t *obj_p = ECMA_GET_POINTER(value.value);
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER(value.value);
JERRY_ASSERT(obj_p != NULL);
if (do_ref_if_object)
@@ -259,14 +259,14 @@ ecma_free_value (ecma_value_t value, /**< value description */
case ECMA_TYPE_NUMBER:
{
ecma_number_t *number_p = ECMA_GET_POINTER(value.value);
ecma_number_t *number_p = ECMA_GET_NON_NULL_POINTER(value.value);
ecma_dealloc_number (number_p);
break;
}
case ECMA_TYPE_STRING:
{
ecma_string_t *string_p = ECMA_GET_POINTER(value.value);
ecma_string_t *string_p = ECMA_GET_NON_NULL_POINTER(value.value);
ecma_deref_ecma_string (string_p);
break;
}
@@ -275,7 +275,7 @@ ecma_free_value (ecma_value_t value, /**< value description */
{
if (do_deref_if_object)
{
ecma_deref_object (ECMA_GET_POINTER(value.value));
ecma_deref_object (ECMA_GET_NON_NULL_POINTER(value.value));
}
break;
}
@@ -497,7 +497,7 @@ ecma_free_completion_value (ecma_completion_value_t completion_value) /**< compl
case ECMA_COMPLETION_TYPE_CONTINUE:
case ECMA_COMPLETION_TYPE_BREAK:
{
ecma_dealloc_label_descriptor (ECMA_GET_POINTER (completion_value.u.label_desc_cp));
ecma_dealloc_label_descriptor (ECMA_GET_NON_NULL_POINTER (completion_value.u.label_desc_cp));
break;
}
case ECMA_COMPLETION_TYPE_META:
+8 -8
View File
@@ -530,11 +530,11 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
if (property_p->type == ECMA_PROPERTY_NAMEDDATA)
{
property_name_p = ECMA_GET_POINTER(property_p->u.named_data_property.name_p);
property_name_p = ECMA_GET_NON_NULL_POINTER(property_p->u.named_data_property.name_p);
}
else if (property_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
{
property_name_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.name_p);
property_name_p = ECMA_GET_NON_NULL_POINTER(property_p->u.named_accessor_property.name_p);
}
else
{
@@ -606,7 +606,7 @@ ecma_free_named_data_property (ecma_property_t *property_p) /**< the property */
{
JERRY_ASSERT(property_p->type == ECMA_PROPERTY_NAMEDDATA);
ecma_deref_ecma_string (ECMA_GET_POINTER (property_p->u.named_data_property.name_p));
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (property_p->u.named_data_property.name_p));
ecma_free_value (property_p->u.named_data_property.value, false);
ecma_dealloc_property (property_p);
@@ -620,7 +620,7 @@ ecma_free_named_accessor_property (ecma_property_t *property_p) /**< the propert
{
JERRY_ASSERT(property_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
ecma_deref_ecma_string (ECMA_GET_POINTER (property_p->u.named_accessor_property.name_p));
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (property_p->u.named_accessor_property.name_p));
ecma_dealloc_property (property_p);
} /* ecma_free_named_accessor_property */
@@ -641,7 +641,7 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* a collection */
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* a collection */
{
ecma_free_values_collection (ECMA_GET_POINTER(property_value), true);
ecma_free_values_collection (ECMA_GET_NON_NULL_POINTER(property_value), true);
break;
}
@@ -650,14 +650,14 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
{
if (property_value != ECMA_NULL_POINTER)
{
ecma_free_values_collection (ECMA_GET_POINTER(property_value), false);
ecma_free_values_collection (ECMA_GET_NON_NULL_POINTER(property_value), false);
}
break;
}
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
{
ecma_string_t *str_p = ECMA_GET_POINTER (property_value);
ecma_string_t *str_p = ECMA_GET_NON_NULL_POINTER (property_value);
ecma_deref_ecma_string (str_p);
break;
@@ -665,7 +665,7 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* pointer to a ecma_number_t */
{
ecma_number_t *num_p = ECMA_GET_POINTER (property_value);
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER (property_value);
ecma_dealloc_number (num_p);
break;
+14 -8
View File
@@ -26,11 +26,24 @@
#include "ecma-globals.h"
#include "mem-allocator.h"
/**
* Get value of pointer from specified non-null compressed pointer field.
*/
#define ECMA_GET_NON_NULL_POINTER(field) \
(mem_decompress_pointer (field))
/**
* Get value of pointer from specified compressed pointer field.
*/
#define ECMA_GET_POINTER(field) \
((unlikely (field == ECMA_NULL_POINTER)) ? NULL : mem_decompress_pointer (field))
((unlikely (field == ECMA_NULL_POINTER)) ? NULL : ECMA_GET_NON_NULL_POINTER (field))
/**
* Set value of non-null compressed pointer field so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \
(field) = (mem_compress_pointer (non_compressed_pointer) & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1))
/**
* Set value of compressed pointer field so that it will correspond
@@ -47,13 +60,6 @@
: (mem_compress_pointer (non_compressed_pointer) \
& ((1u << ECMA_POINTER_FIELD_WIDTH) - 1)))
/**
* Set value of non-null compressed pointer field so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \
(field) = (mem_compress_pointer (non_compressed_pointer) & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1))
/* ecma-helpers-value.c */
extern bool ecma_is_value_empty (ecma_value_t value);
extern bool ecma_is_value_undefined (ecma_value_t value);