Codebergdnkl

foot

master
ply5 git calls29 ms29 KiB3 cachedprotocol v2
149 lines3.2 KiBRaw
1#include "composed.h"
3#include <stdlib.h>
4#include <stdbool.h>
6#include "debug.h"
7#include "terminal.h"
9uint32_t
10composed_key_from_chars(const uint32_t chars[], size_t count)
12 if (count == 0)
13 return 0;
15 uint32_t key = chars[0];
16 for (size_t i = 1; i < count; i++)
17 key = composed_key_from_key(key, chars[i]);
19 return key;
22uint32_t
23composed_key_from_key(uint32_t prev_key, uint32_t next_char)
25 unsigned bits = 32 - __builtin_clz(CELL_COMB_CHARS_HI - CELL_COMB_CHARS_LO);
27 /* Rotate old key 8 bits */
28 uint32_t new_key = (prev_key << 8) | (prev_key >> (bits - 8));
30 /* xor with new char */
31 new_key ^= next_char;
33 /* Multiply with magic hash constant */
34 new_key *= 2654435761ul;
36 /* And mask, to ensure the new value is within range */
37 new_key &= CELL_COMB_CHARS_HI - CELL_COMB_CHARS_LO;
38 return new_key;
41UNITTEST
43 const char32_t chars[] = U"abcdef";
45 uint32_t k1 = composed_key_from_key(chars[0], chars[1]);
46 uint32_t k2 = composed_key_from_chars(chars, 2);
47 xassert(k1 == k2);
49 uint32_t k3 = composed_key_from_key(k2, chars[2]);
50 uint32_t k4 = composed_key_from_chars(chars, 3);
51 xassert(k3 == k4);
54const struct composed *
55composed_lookup(struct composed *root, uint32_t key)
57 struct composed *node = root;
59 while (node != NULL) {
60 if (key == node->key)
61 return node;
63 node = key < node->key ? node->left : node->right;
64 }
66 return NULL;
69const struct composed *
70composed_lookup_without_collision(struct composed *root, uint32_t *key,
71 const char32_t *prefix_text, size_t prefix_len,
72 char32_t wc, int forced_width)
74 while (true) {
75 const struct composed *cc = composed_lookup(root, *key);
76 if (cc == NULL)
77 return NULL;
79 bool match = cc->count == prefix_len + 1 &&
80 cc->forced_width == forced_width &&
81 cc->chars[prefix_len] == wc;
83 if (match) {
84 for (size_t i = 0; i < prefix_len; i++) {
85 if (cc->chars[i] != prefix_text[i]) {
86 match = false;
87 break;
88 }
89 }
90 }
92 if (match)
93 return cc;
95 (*key)++;
96 *key &= CELL_COMB_CHARS_HI - CELL_COMB_CHARS_LO;
98 /* TODO: this will loop infinitely if the composed table is full */
99 }
101 return NULL;
104void
105composed_insert(struct composed **root, struct composed *node)
107 node->left = node->right = NULL;
109 if (*root == NULL) {
110 *root = node;
111 return;
112 }
114 uint32_t key = node->key;
116 struct composed *prev = NULL;
117 struct composed *n = *root;
119 while (n != NULL) {
120 xassert(n->key != node->key);
122 prev = n;
123 n = key < n->key ? n->left : n->right;
124 }
126 xassert(prev != NULL);
127 xassert(n == NULL);
129 if (key < prev->key) {
130 xassert(prev->left == NULL);
131 prev->left = node;
132 } else {
133 xassert(prev->right == NULL);
134 prev->right = node;
135 }
138void
139composed_free(struct composed *root)
141 if (root == NULL)
142 return;
144 composed_free(root->left);
145 composed_free(root->right);
147 free(root->chars);
148 free(root);
Diagnostics5 git calls · 29 ms
CallStatusSizeTime029 ms
discover200178 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=178
git.server.agent=git/2.56.1-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=178
git.pkt.payload.max=35
ls-refs20010 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=10322
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=108
git.pkt.data=107
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=10322
git.pkt.payload.max=106
git.ls_refs.count=107
git.ls_refs.head=refs/heads/master
fetchcombine:blob:none+tree:2 · deepen 12008.6 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=8830
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=8830
git.pkt.payload.max=8730
git.sideband.band1.bytes=8730
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=14
git.pack.bytes=8730
git.fetch.wide.objects=14
git.fetch.wide.extra_bytes=9909
git.fetch.wide.blobs=0
fetchtree:0 · deepen 102009.3 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=25
git.response.bytes=9489
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=9489
git.pkt.payload.max=9389
git.sideband.band1.bytes=9389
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=9389
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=de930681b6073ba5b599a0f956bfbd114762ad5a
git.pack.full=10
Open pack map
fetch2001.1 KiB · hit25 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1131
git.response.cache=HIT
git.response.duration_ms=25
git.fetch.wants=fc7dfa00ef0c924ff5ebb9e2746c77b015c3aefb
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1131
git.pkt.payload.max=1104
git.sideband.band1.bytes=1104
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://codeberg.org/dnkl/foot
Ref
refs/heads/master
Commit
c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
cf-ray
a5e22c714d152a83
Request
b23b286e…
Protocol
v2 · sha1
Agent
git/2.56.1-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format