aboutsummaryrefslogtreecommitdiff
path: root/src/blob.zig
blob: 9e0eba40707923566633eea7e149040e87194fba (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const std = @import("std");
const Lock = @import("./lock.zig").Lock;
usingnamespace @import("./global.zig");

const Blob = @This();

ptr: [*]const u8,
len: usize,

pub const Map = struct {
    const MapContext = struct {
        pub fn hash(self: @This(), s: u64) u32 {
            return @truncate(u32, s);
        }
        pub fn eql(self: @This(), a: u64, b: u64) bool {
            return a == b;
        }
    };

    const HashMap = std.ArrayHashMap(u64, Blob, MapContext, false);
    lock: Lock,
    map: HashMap,
    allocator: *std.mem.Allocator,

    pub fn init(allocator: *std.mem.Allocator) Map {
        return Map{
            .lock = Lock.init(),
            .map = HashMap.init(allocator),
            .allocator = allocator,
        };
    }

    pub fn get(this: *Map, key: string) ?Blob {
        this.lock.lock();
        defer this.lock.unlock();
        return this.map.get(std.hash.Wyhash.hash(0, key));
    }

    pub fn put(this: *Map, key: string, blob: Blob) !void {
        this.lock.lock();
        defer this.lock.unlock();

        return try this.map.put(std.hash.Wyhash.hash(0, key), blob);
    }

    pub fn reset(this: *Map) !void {
        this.lock.lock();
        defer this.lock.unlock();
        this.map.clearRetainingCapacity();
    }
};

pub const Group = struct {
    persistent: Map,
    temporary: Map,
    allocator: *std.mem.Allocator,

    pub fn init(allocator: *std.mem.Allocator) !*Group {
        var group = try allocator.create(Group);
        group.* = Group{ .persistent = Map.init(allocator), .temporary = Map.init(allocator), .allocator = allocator };
        return group;
    }

    pub fn get(this: *Group, key: string) ?Blob {
        return this.temporary.get(key) orelse this.persistent.get(key);
    }
};
chore: dead code * fix: order of default config properties * refactor: move md defaults to remark * fix: RemarkRehype type * fix: apply defaults based on MD defaults * chore: update plugin tests * chore: add syntaxHighlight test * refactor: remove drafts from config defaults * docs: new MDX config options * chore: add changeset * edit: test both extends for syntax highlight * refactor: remove MDX config deep merge * docs: update README and changeset * edit: avoid -> disable Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * edit: `drafts` clarification Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * edit: remove "scare quotes" Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * docs: MDX config options redraft * docs: add migration * chore: changeset heading levels * refactor: githubFlavoredMarkdown -> gfm * chore: remove unused imports Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> 2023-01-03[ci] formatGravatar bholmesdev 4-46/+45 2023-01-03Change frontmatter injection ordering (#5687)Gravatar Ben Holmes 29-204/+234 * feat: make user frontmatter accessible in md * test: new frontmatter injection * refactor: move injection utils to remark pkg * fix: add dist/internal to remark exports * feat: update frontmater injection in mdx * tests: new mdx injection * chore: changeset * chore: simplify frontmatter destructuring * fix: remove old _internal references * refactor: injectedFrontmatter -> remarkPluginFrontmatter * docs: add content collections change * chore: changeset heading levels 2023-01-03Cleanup internal breaking changes (#5724)Gravatar Bjorn Lu 4-33/+7 * Remove Astro.glob template literal trick * Remove RenderTemplateResult toString * Remove astro add volar warning * Add changeset 2023-01-03Fix astro-embed peerDep issue (#5731)Gravatar Matthew Phillips 2-2/+2 * Fix astro-embed peerDep issue * Update lockfile 2023-01-03Fix missing ts flag on main (#5730)Gravatar Matthew Phillips 1-0/+1 2023-01-03[ci] formatGravatar matthewp 3-10/+2 2023-01-03Remove MDX Fragment hack (#5716)Gravatar Bjorn Lu 2-9/+6 * Remove MDX Fragment hack * Update .changeset/lovely-terms-drive.md Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> 2023-01-03Remove deprecated APIs (#5707)Gravatar Bjorn Lu 18-217/+87 * Remove deprecated Astro globals * Remove deprecated hook param * Fix test * Add changeset * Add TODO 2023-01-03Unflag experimental features (#5728)Gravatar Nate Moore 13-122/+26 * feat: unflag `--experimental-error-overlay` * feat: unflag `--experimental-prerender` * chore: add changeset * Update chilled-geese-worry.md * test: update test to use `mjs` * Update .changeset/chilled-geese-worry.md Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * Update chilled-geese-worry.md Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> 2023-01-03Upgrade to Vite 4 (#5685)Gravatar Bjorn Lu 21-3459/+337 * Upgrade Vite 4 * Simplify Svelte preprocess setup * Upgrade rollup * Fix tests * Fix wrong changeset target * Fix error tests * Set NODE_ENV default 2023-01-03[ci] update lockfile (#5686)Gravatar Fred K. Bot 4-3215/+2864 * [ci] update lockfile * Fix build errors from new TypeScript version * Updated lockfile Co-authored-by: FredKSchott <FredKSchott@users.noreply.github.com> Co-authored-by: Matthew Phillips <matthew@skypack.dev>