bin/varnishd/hpack/vhp_table.c
static void
vht_trim(struct vht_table *tbl, ssize_t max)
{
	unsigned u, v;
	int i;
	struct vht_entry *e;

	CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC);

	if (max < 0)
		max = 0;
	if (TBLSIZE(tbl) <= max)
		return;

	u = v = 0;
	for (i = tbl->n - 1; i >= 0; i--) {
		e = TBLENTRY(tbl, i);
		CHECK_OBJ_NOTNULL(e, VHT_ENTRY_MAGIC);
		if (TBLSIZE(tbl) - (u + v * VHT_ENTRY_SIZE) > max) {
			/* Trim entry */
			assert(e->offset == u);
			u += ENTRYLEN(e);
			v++;
			FINI_OBJ(e);
		} else {
			/* Fixup offset */
			assert(e->offset >= u);
			e->offset -= u;
		}
	}
	assert(v <= tbl->n);

	memmove(tbl->buf, tbl->buf + u, tbl->size - u);
	memmove(TBLENTRY(tbl, v), TBLENTRY(tbl, 0), (tbl->n - v) * sizeof *e);
	tbl->n -= v;
	tbl->size -= u;
}
/* Trim elements from the end until the table size is less than max. */
Trim elements from the end until the table size is less than max.
Trim elements from the end until the table size is less than max .
static void
vht_trim(struct vht_table *tbl, ssize_t max)
{
	unsigned u, v;
	int i;
	struct vht_entry *e;
	CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC);
	if (max < 0)
		max = 0;
	if (TBLSIZE(tbl) <= max)
		return;
	u = v = 0;
	for (i = tbl->n - 1; i >= 0; i--) {
		e = TBLENTRY(tbl, i);
		CHECK_OBJ_NOTNULL(e, VHT_ENTRY_MAGIC);
		if (TBLSIZE(tbl) - (u + v * VHT_ENTRY_SIZE) > max) {
			assert(e->offset == u);
			u += ENTRYLEN(e);
			v++;
			FINI_OBJ(e);
		} else {
			assert(e->offset >= u);
			e->offset -= u;
		}
	}
	assert(v <= tbl->n);
	memmove(tbl->buf, tbl->buf + u, tbl->size - u);
	memmove(TBLENTRY(tbl, v), TBLENTRY(tbl, 0), (tbl->n - v) * sizeof *e);
	tbl->n -= v;
	tbl->size -= u;
}
static void vht_trim ( struct vht_table * tbl , ssize_t max ) { unsigned u , v ; int i ; struct vht_entry * e ; CHECK_OBJ_NOTNULL ( tbl , VHT_TABLE_MAGIC ) ; if ( max < 0 ) max = 0 ; if ( TBLSIZE ( tbl ) <= max ) return ; u = v = 0 ; for ( i = tbl -> n - 1 ; i >= 0 ; i -- ) { e = TBLENTRY ( tbl , i ) ; CHECK_OBJ_NOTNULL ( e , VHT_ENTRY_MAGIC ) ; if ( TBLSIZE ( tbl ) - ( u + v * VHT_ENTRY_SIZE ) > max ) { assert ( e -> offset == u ) ; u += ENTRYLEN ( e ) ; v ++ ; FINI_OBJ ( e ) ; } else { assert ( e -> offset >= u ) ; e -> offset -= u ; } } assert ( v <= tbl -> n ) ; memmove ( tbl -> buf , tbl -> buf + u , tbl -> size - u ) ; memmove ( TBLENTRY ( tbl , v ) , TBLENTRY ( tbl , 0 ) , ( tbl -> n - v ) * sizeof * e ) ; tbl -> n -= v ; tbl -> size -= u ; }
Trim elements from the end until the table size is less than max.
Trim elements from the end until the table size is less than max .
/* Trim entry */ /* Fixup offset */