Changeset 543
- Timestamp:
- 01/31/09 12:39:18 (3 years ago)
- Files:
-
- trunk/tempAlloc/tempAlloc.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tempAlloc/tempAlloc.d
r538 r543 62 62 capacity = max(16, capacity * 2); 63 63 data = cast(T*) ntRealloc(data, capacity * sz, cast(GC.BlkAttr) 0); 64 data[index..capacity] = T.init; // Prevent false ptrs. 64 65 } 65 66 data[index++] = elem; … … 67 68 68 69 T pop() nothrow { 69 return data[--index]; 70 index--; 71 auto ret = data[index]; 72 data[index] = T.init; // Prevent false ptrs. 73 return ret; 70 74 } 71 75 } 72 76 73 77 struct Block { 74 size_t used ;75 void* space ;78 size_t used = 0; 79 void* space = null; 76 80 } 77 81 … … 332 336 } 333 337 334 /**Creates a duplicate of an array on the TempAlloc struct.*/ 338 /**Concatenate any number of arrays of the same type, placing results on 339 * the TempAlloc stack.*/ 340 T[0] stackCat(T...)(T data) { 341 foreach(array; data) { 342 static assert(is(typeof(array) == typeof(data[0]))); 343 } 344 345 size_t totalLen = 0; 346 foreach(array; data) { 347 totalLen += array.length; 348 } 349 auto ret = newStack!(Mutable!(typeof(T[0][0])))(totalLen); 350 351 size_t offset = 0; 352 foreach(array; data) { 353 ret[offset..offset + array.length] = array[0..$]; 354 offset += array.length; 355 } 356 return cast(T[0]) ret; 357 } 358 359 /**Creates a duplicate of an array on the TempAlloc stack.*/ 335 360 auto tempdup(T)(T[] data) nothrow { 336 361 alias Mutable!(T) U;
