| 172 | #define kParserChunkSize (4096) |
| 173 | |
| 174 | void* fxNewParserChunk(txParser* parser, txSize size) |
| 175 | { |
| 176 | size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1); |
| 177 | if (size <= parser->chunkSize) { |
| 178 | void *result = parser->chunk; |
| 179 | parser->chunk += size; |
| 180 | parser->chunkSize -= size; |
| 181 | return result; |
| 182 | } |
| 183 | |
| 184 | if (size > (txSize)(kParserChunkSize - sizeof(txParserChunk))) { |
| 185 | txParserChunk *block = c_malloc(sizeof(txParserChunk) + size); |
| 186 | if (!block) |
| 187 | fxAbort(parser->console, XS_NOT_ENOUGH_MEMORY_EXIT); |
| 188 | parser->total += sizeof(txParserChunk) + size; |
| 189 | block->next = parser->first; |
| 190 | parser->first = block; |
| 191 | return block + 1; |
| 192 | } |
| 193 | |
| 194 | txParserChunk *block = c_malloc(kParserChunkSize); |
| 195 | if (!block) |
| 196 | fxAbort(parser->console, XS_NOT_ENOUGH_MEMORY_EXIT); |
| 197 | parser->total += kParserChunkSize; |
| 198 | block->next = parser->first; |
| 199 | parser->first = block; |
| 200 | parser->chunk = (txByte*)(block + 1) + size; |
| 201 | parser->chunkSize = kParserChunkSize - sizeof(txParserChunk) - size; |
| 202 | return block + 1; |
| 203 | } |
| 204 | |
| 205 | void* fxNewParserChunkClear(txParser* parser, txSize size) |
| 206 | { |
no test coverage detected