aboutsummaryrefslogtreecommitdiff
path: root/src/max_heap_allocator.zig
blob: ea616c9ca8d521f3dc554db1822cef77b970a30f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const bun = @import("root").bun;
const std = @import("std");

/// Single allocation only.
///
pub const MaxHeapAllocator = struct {
    array_list: std.ArrayList(u8),

    fn alloc(ptr: *anyopaque, len: usize, _: u8, _: usize) ?[*]u8 {
        var this = bun.cast(*MaxHeapAllocator, ptr);
        this.array_list.items.len = 0;
        this.array_list.ensureTotalCapacity(len) catch return null;
        this.array_list.items.len = len;
        return this.array_list.items.ptr;
    }

    fn resize(_: *anyopaque, buf: []u8, _: u8, new_len: usize, _: usize) bool {
        _ = new_len;
        _ = buf;
        @panic("not implemented");
    }

    fn free(
        _: *anyopaque,
        _: []u8,
        _: u8,
        _: usize,
    ) void {}

    pub fn reset(this: *MaxHeapAllocator) void {
        this.array_list.items.len = 0;
    }

    pub fn deinit(this: *MaxHeapAllocator) void {
        this.array_list.deinit();
    }

    const vtable = std.mem.Allocator.VTable{
        .alloc = &alloc,
        .free = &free,
        .resize = &resize,
    };
    pub fn init(this: *MaxHeapAllocator, allocator: std.mem.Allocator) std.mem.Allocator {
        this.array_list = std.ArrayList(u8).init(allocator);

        return std.mem.Allocator{
            .ptr = this,
            .vtable = &vtable,
        };
    }
};
Improve Collection docs for RSS (#990)Gravatar Joshua Stübner 1-1/+5 2021-08-03Improve code sample for lit integration (#991)Gravatar tobi-or-not-tobi 1-4/+6 2021-08-03fix: Exclude remote srcset URLs (#986)Gravatar Maarten Van Hoof 2-1/+8 2021-08-03Make Astro.request available to all astro components (#960)Gravatar Matthew Phillips 7-15/+53 2021-08-02Add `lang` variable to docs frontmatter for translations (#984)Gravatar Caleb Jasik 4-0/+4 2021-08-01Update styling.md re link-handling for .scss files (#977)Gravatar Bryce Wray 1-1/+3 2021-08-01add support for 4-letter language codes (ex: zh-TW)Gravatar Fred K. Schott 1-1/+1 2021-08-02[ci] yarn formatGravatar FredKSchott 3-11/+10 2021-08-01full translation (#967)Gravatar Fred K. Schott 9-83/+85 2021-08-01Update CONTRIBUTING.mdGravatar Fred K. Schott 1-3/+3 2021-08-02[ci] yarn formatGravatar FredKSchott 1-3/+1 2021-08-01Update and rename contributing.md to CONTRIBUTING.mdGravatar Fred K. Schott 1-0/+29 2021-08-01Delete COMMUNITY.mdGravatar Fred K. Schott 1-15/+0 2021-07-31fix bad merge from outdated layoutGravatar Fred K. Schott 3-3/+3 2021-07-30Fixes throwing 404 (#894)Gravatar Maciej Palmowski 1-3/+0 2021-07-30small cleanup to installation docsGravatar Fred K. Schott 1-9/+6 2021-07-30add finnish to language selectorGravatar Fred K. Schott 2-2/+5 2021-07-30move finnish translations to fiGravatar Fred K. Schott 3-0/+0 2021-07-30WIP: Documentation in Finnish (#837)Gravatar Vesa Piittinen 3-0/+201 2021-07-30📘 DOC: Add PostCSS configuration on Astro (#947)Gravatar Diogo Felix 1-0/+27 2021-07-30fix styling URL linkGravatar Fred K. Schott 1-1/+1 2021-07-31[ci] yarn formatGravatar FredKSchott 6-36/+61 2021-07-30fix styling guide (#961)Gravatar Rubens de Melo 1-1/+1 2021-07-30Add svelte file extension to tailwind puge configuration. (#964)Gravatar allanvobraun 1-1/+1 2021-07-30Docs site cleanup (#948)Gravatar Fred K. Schott 57-730/+739 2021-07-30Ascii quotes (#928)Gravatar Marcus Otterström 8-63/+63 2021-07-30forced degit template extraction in case of non empty installation directory ...Gravatar mash-graz 2-23/+7 2021-07-30Version Packages (#940)Gravatar github-actions[bot] 26-34/+45 2021-07-30[ci] yarn formatGravatar matthewp 1-1/+1 2021-07-30Fix Vue components nesting and add tests (#924)Gravatar Bartek Igielski 10-34/+171 2021-07-30[ci] yarn formatGravatar FredKSchott 1-1/+0 2021-07-30Fix typos and clarify docs (#880)Gravatar Marcus Otterström 4-4/+5 2021-07-29move translated nl docsGravatar Fred K. Schott 3-1/+1