-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored and unit-tested filter_special_opts. Shaved a bunch of yak…
…s on the way.
- Loading branch information
Showing
15 changed files
with
413 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "arena.h" | ||
|
||
struct block { | ||
size_t size; | ||
size_t used; | ||
struct block *next; | ||
char data_start[]; | ||
}; | ||
|
||
static const size_t min_block_room = 16 * 1024 - sizeof(struct block); | ||
|
||
static void add_block(struct arena* a, size_t room_wanted) | ||
{ | ||
if (room_wanted < min_block_room) { | ||
room_wanted = min_block_room; | ||
} | ||
struct block *new_block = malloc(sizeof(struct block) + room_wanted); | ||
new_block->size = room_wanted; | ||
new_block->used = 0; | ||
new_block->next = a->cur_block; | ||
a->cur_block = new_block; | ||
} | ||
|
||
void arena_init(struct arena *a) | ||
{ | ||
a->cur_block = NULL; | ||
} | ||
|
||
void* arena_malloc(struct arena *a, size_t amount) | ||
{ | ||
struct block* b = a->cur_block; | ||
if (b == NULL || b->size - b->used < amount) { | ||
add_block(a, amount); | ||
b = a->cur_block; | ||
} | ||
void* result = &b->data_start[b->used]; | ||
b->used += amount; | ||
return result; | ||
} | ||
|
||
void arena_free(struct arena *a) | ||
{ | ||
struct block* b = a->cur_block; | ||
while (b != NULL) { | ||
struct block* next = b->next; | ||
free(b); | ||
b = next; | ||
} | ||
a->cur_block = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef INC_BINDFS_ARENA_H | ||
#define INC_BINDFS_ARENA_H | ||
|
||
#include <stdlib.h> | ||
|
||
struct block; | ||
struct arena { | ||
struct block *cur_block; | ||
}; | ||
|
||
void arena_init(struct arena *a); | ||
void* arena_malloc(struct arena *a, size_t amount); | ||
void arena_free(struct arena *a); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.