Skip to content
VecInsertRangeFastL

VecInsertRangeFastL

Description

Insert a range using fast (order-not-preserving) placement. L-value form. The original tail-count elements of the vector are moved past the inserted region instead of having every element after idx shifted; iteration order is no longer meaningful.

Success

Returns true. The vector length grows by count; the inserted elements occupy [idx, idx + count), and the displaced elements sit somewhere in the new tail (no defined relative order). When the vector has no copy_init handler, the count * sizeof(element) source bytes have been zeroed.

Failure

Returns false on allocation failure. Both vector and source are unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
    /// TAGS: Vec, Insert, Range, Fast
    ///
    #define VecInsertRangeFast(v, varr, idx, count) VecInsertRangeFastL((v), (varr), (idx), (count))
    
    ///
    /// TAGS: Vec, PushFront, Range, LValue, Fast, Unordered
    ///
    #define VecPushFrontArrFastL(v, arr, count) VecInsertRangeFastL((v), (arr), 0, (count))
    
    ///
    #define VecMustInsertRangeFastL(v, varr, idx, count)                                                                   \
        do {                                                                                                               \
            if (!VecInsertRangeFastL((v), (varr), (idx), (count))) {                                                       \
                LOG_FATAL("VecMustInsertRangeFastL failed");                                                               \
            }                                                                                                              \
    /// TAGS: Str, Insert, Range, LValue, Fast, Unordered
    ///
    #define StrInsertRangeFastL(str, varr, idx, count) VecInsertRangeFastL((str), (varr), (idx), (count))
    
    ///
        // Test VecInsertRangeFastL
        int fast_range[] = {110, 120, 130};
        VecInsertRangeFastL(&vec, fast_range, 3, 3);
    
        // Check that array elements are zeroed
    // vec_insert_range_l, fast (non-preserve) path.
    bool test_insert_range_l_fast_inserts_all(void) {
        WriteFmt("Testing VecInsertRangeFastL inserts all items\n");
    
        DefaultAllocator local = DefaultAllocatorInit();
    
        u32  items[] = {444u, 555u, 666u};
        bool ok      = VecInsertRangeFastL(&vec, items, 0, 3);
    
        // Fast insert into an empty vector keeps order, so a direct index
    // is false.
    bool test_insert_range_fast_l_reports_failure(void) {
        WriteFmt("Testing VecInsertRangeFastL reports copy_init failure (603:32)\n");
    
        // Canary allocator: the empty-vec / idx==length failure path also pins the
        g_fail           = true;
        MutElem items[2] = {{.value = 10}, {.value = 20}};
        bool    ok       = VecInsertRangeFastL(&vec, items, 0, 2);
        g_fail           = false;
Last updated on