MCPcopy Create free account
hub / github.com/buke/quickjs-go / build_prop_table

Function build_prop_table

deps/quickjs/unicode_gen.c:1471–1569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1469#define PROP_BLOCK_LEN 32
1470
1471void build_prop_table(FILE *f, int prop_index, bool add_index)
1472{
1473 int i, j, n, v, offset, code;
1474 DynBuf dbuf_s, *dbuf = &dbuf_s;
1475 DynBuf dbuf1_s, *dbuf1 = &dbuf1_s;
1476 DynBuf dbuf2_s, *dbuf2 = &dbuf2_s;
1477 const uint32_t *buf;
1478 int buf_len, block_end_pos, bit;
1479 char cname[128];
1480
1481 dbuf_init(dbuf1);
1482
1483 for(i = 0; i <= CHARCODE_MAX;) {
1484 v = get_prop(i, prop_index);
1485 j = i + 1;
1486 while (j <= CHARCODE_MAX && get_prop(j, prop_index) == v) {
1487 j++;
1488 }
1489 n = j - i;
1490 if (j == (CHARCODE_MAX + 1) && v == 0)
1491 break; /* no need to encode last zero run */
1492 //printf("%05x: %d %d\n", i, n, v);
1493 dbuf_put_u32(dbuf1, n - 1);
1494 i += n;
1495 }
1496
1497 dbuf_init(dbuf);
1498 dbuf_init(dbuf2);
1499 buf = (uint32_t *)dbuf1->buf;
1500 buf_len = dbuf1->size / sizeof(buf[0]);
1501
1502 /* the first value is assumed to be 0 */
1503 assert(get_prop(0, prop_index) == 0);
1504
1505 block_end_pos = PROP_BLOCK_LEN;
1506 i = 0;
1507 code = 0;
1508 bit = 0;
1509 while (i < buf_len) {
1510 if (add_index && dbuf->size >= block_end_pos && bit == 0) {
1511 offset = (dbuf->size - block_end_pos);
1512 /* XXX: offset could be larger in case of runs of small
1513 lengths. Could add code to change the encoding to
1514 prevent it at the expense of one byte loss */
1515 assert(offset <= 7);
1516 v = code | (offset << 21);
1517 dbuf_putc(dbuf2, v);
1518 dbuf_putc(dbuf2, v >> 8);
1519 dbuf_putc(dbuf2, v >> 16);
1520 block_end_pos += PROP_BLOCK_LEN;
1521 }
1522
1523 v = buf[i];
1524 code += v + 1;
1525 bit ^= 1;
1526 if (v < 8 && (i + 1) < buf_len && buf[i + 1] < 8) {
1527 code += buf[i + 1] + 1;
1528 bit ^= 1;

Callers 2

build_flags_tablesFunction · 0.85
build_prop_list_tableFunction · 0.85

Calls 7

dbuf_initFunction · 0.85
get_propFunction · 0.85
dbuf_put_u32Function · 0.85
dbuf_putcFunction · 0.85
dump_byte_tableFunction · 0.85
dbuf_freeFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected