Ver código fonte

optimize empty array allocation (singleton)

Nicolas Cannasse 3 anos atrás
pai
commit
498b92c2b7
1 arquivos alterados com 4 adições e 0 exclusões
  1. 4 0
      src/std/array.c

+ 4 - 0
src/std/array.c

@@ -22,6 +22,10 @@
 #include <hl.h>
 
 HL_PRIM varray *hl_alloc_array( hl_type *at, int size ) {
+	if( size == 0 && at->kind == HDYN ) {
+		static varray empty_array = { &hlt_array, &hlt_dyn };
+		return &empty_array;
+	}
 	int esize = hl_type_size(at);
 	varray *a;
 	if( size < 0 ) hl_error("Invalid array size");