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

Code before:
#include "ecma-arraybuffer-object.h"
#include "ecma-shared-arraybuffer-object.h"
#include "ecma-typedarray-object.h"
#include "ecma-objects.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jmem.h"
#include "jcontext.h"
#include "ecma-function-object.h"

#if JERRY_BUILTIN_TYPEDARRAY

/** \addtogroup ecma ECMA
 * @{
 *
 * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines
 * @{
 */

extern inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_is_array_or_sharedarray_buffer (const jerry_value_t value)
{
  if (ecma_is_arraybuffer (value))
  {
    return true;
  }
  #if JERRY_BUILTIN_SHAREDARRAYBUFFER
  if (ecma_is_shared_arraybuffer (value))
  {
    return true;
  }
  #endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */
  return false;
} /* ecma_is_array_or_sharedarray_buffer */

extern inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_is_object_array_or_sharedarray_buffer (ecma_object_t *object)
{
  if (ecma_object_class_is (object, ECMA_OBJECT_CLASS_ARRAY_BUFFER))
  {
    return true;
  }
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
  if (ecma_object_class_is (object, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER))
  {
    return true;
  }
#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */

Review comment (suggestion):
This is shorter:
```
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
  return (ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value));
#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */
  return ecma_is_arraybuffer (value);
#endif /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */
```

Code after:
#include "ecma-arraybuffer-object.h"
#include "ecma-shared-arraybuffer-object.h"
#include "ecma-typedarray-object.h"
#include "ecma-objects.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jmem.h"
#include "jcontext.h"
#include "ecma-function-object.h"

#if JERRY_BUILTIN_TYPEDARRAY

/** \addtogroup ecma ECMA
 * @{
 *
 * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines
 * @{
 */

/**
 * Helper function: create arraybuffer object based on the array length
 *
 * The struct of arraybuffer object:
 *   ecma_object_t
 *   extend_part
 *   data buffer
 *
 * @return ecma_object_t *
 */
ecma_object_t *
ecma_arraybuffer_new_object (uint32_t length) /**< length of the arraybuffer */
{
  ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE);
  ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
                                                sizeof (ecma_extended_object_t) + length,
                                                ECMA_OBJECT_TYPE_CLASS);

  ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
  ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_ARRAY_BUFFER;
  ext_object_p->u.cls.u1.array_buffer_flags = ECMA_ARRAYBUFFER_INTERNAL_MEMORY;
  ext_object_p->u.cls.u3.length = length;

  lit_utf8_byte_t *buf = (lit_utf8_byte_t *) (ext_object_p + 1);
  memset (buf, 0, length);

  return object_p;
} /* ecma_arraybuffer_new_object */