* buf_extend() -- Enlarge the memory allocated to a buffer. * Return how many bytes are added to the buffer. */
| 1978 | * Return how many bytes are added to the buffer. |
| 1979 | */ |
| 1980 | static uint16 |
| 1981 | buf_extend(BMTIDBuffer *buf) |
| 1982 | { |
| 1983 | uint16 bytes; |
| 1984 | uint16 size; |
| 1985 | |
| 1986 | if (buf->num_cwords > 0 && buf->curword < buf->num_cwords - 1) |
| 1987 | return 0; /* already large enough */ |
| 1988 | |
| 1989 | if(buf->num_cwords == 0) |
| 1990 | { |
| 1991 | size = BUF_INIT_WORDS; |
| 1992 | buf->cwords = (BM_HRL_WORD *) |
| 1993 | palloc0(BUF_INIT_WORDS * sizeof(BM_HRL_WORD)); |
| 1994 | buf->last_tids = (uint64 *)palloc0(BUF_INIT_WORDS * sizeof(uint64)); |
| 1995 | bytes = BUF_INIT_WORDS * sizeof(BM_HRL_WORD) + |
| 1996 | BUF_INIT_WORDS * sizeof(uint64); |
| 1997 | } |
| 1998 | else |
| 1999 | { |
| 2000 | size = buf->num_cwords; |
| 2001 | buf->cwords = repalloc(buf->cwords, 2 * size * sizeof(BM_HRL_WORD)); |
| 2002 | MemSet(buf->cwords + size, 0, size * sizeof(BM_HRL_WORD)); |
| 2003 | buf->last_tids = repalloc(buf->last_tids, 2 * size * sizeof(uint64)); |
| 2004 | MemSet(buf->last_tids + size, 0, size * sizeof(uint64)); |
| 2005 | bytes = 2 * size * sizeof(BM_HRL_WORD) + |
| 2006 | 2 * size * sizeof(uint64); |
| 2007 | } |
| 2008 | buf->num_cwords += size; |
| 2009 | return bytes; |
| 2010 | } |
| 2011 | |
| 2012 | /* |
| 2013 | * Spill some HRL compressed tids to disk |
no test coverage detected