Show
Ignore:
Timestamp:
01/31/09 12:39:18 (3 years ago)
Author:
dsimcha
Message:

Fix false ptr issues. Add stackCat.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tempAlloc/tempAlloc.d

    r538 r543  
    6262                capacity = max(16, capacity * 2); 
    6363                data = cast(T*) ntRealloc(data, capacity * sz, cast(GC.BlkAttr) 0); 
     64                data[index..capacity] = T.init;  // Prevent false ptrs. 
    6465            } 
    6566            data[index++] = elem; 
     
    6768 
    6869        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; 
    7074        } 
    7175    } 
    7276 
    7377    struct Block { 
    74         size_t used
    75         void* space
     78        size_t used = 0
     79        void* space = null
    7680    } 
    7781 
     
    332336} 
    333337 
    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.*/ 
     340T[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.*/ 
    335360auto tempdup(T)(T[] data) nothrow { 
    336361    alias Mutable!(T) U;