瀏覽代碼

* fixed DynArraySetLength

git-svn-id: trunk@1678 -
florian 20 年之前
父節點
當前提交
8b3c634573
共有 1 個文件被更改,包括 13 次插入1 次删除
  1. 13 1
      rtl/inc/dynarr.inc

+ 13 - 1
rtl/inc/dynarr.inc

@@ -339,7 +339,19 @@ function fpc_dynarray_copy(psrc : pointer;ti : pointer;
 
 
 procedure DynArraySetLength(var a: Pointer; typeInfo: Pointer; dimCnt: SizeInt; lengthVec: PSizeInt);
+  var
+    preallocated : array[0..10] of PSizeInt;
+    i : SizeInt;
+    p : PSizeInt;
   begin
-    int_dynarray_setlength(a,typeInfo,dimCnt,lengthVec);
+    if dimCnt<=length(preallocated) then
+      p:=@preallocated
+    else
+      getmem(p,sizeof(SizeInt)*dimCnt);
+    for i:=0 to dimCnt-1 do
+      p[i]:=lengthVec[dimCnt-1-i];
+    int_dynarray_setlength(a,typeInfo,dimCnt,p);
+    if p<>@preallocated then
+      freemem(p);
   end;