njs_array_sort_ctx_t ctx;
njs_array_sort_slot_t *p, *end, *slots, *newslots;
+ njs_assert(length != 0);
+
slots = NULL;
keys = NULL;
ctx.vm = vm;
return ret;
}
+ slots = NULL;
+
+ if (length == 0) {
+ goto done;
+ }
+
/* Satisfy gcc -O3 */
nslots = 0;
}
}
+done:
+
njs_value_assign(retval, this);
ret = NJS_OK;
return NJS_ERROR;
}
- slots = njs_sort_indexed_properties(vm, this, length, compare, 0, &nslots,
- &nunds);
- if (njs_slow_path(slots == NULL)) {
- ret = NJS_ERROR;
- goto exception;
+ if (length != 0) {
+ slots = njs_sort_indexed_properties(vm, this, length, compare, 0,
+ &nslots, &nunds);
+ if (njs_slow_path(slots == NULL)) {
+ ret = NJS_ERROR;
+ goto exception;
+ }
+
+ } else {
+ slots = NULL;
+ length = 0;
+ nslots = 0;
+ nunds = 0;
}
njs_assert(length == (nslots + nunds));
return NULL;
}
+#if (NJS_DEBUG)
+ /*
+ * Ensure that the size is not zero, otherwise njs_mp_find_block()
+ * will not be able to find the block.
+ */
+ size += size == 0;
+#endif
+
if (njs_is_power_of_two(size)) {
block = njs_malloc(sizeof(njs_mp_block_t));
if (njs_slow_path(block == NULL)) {