[parser] storing address_parser_context on the parser struct itself so it doesn't have to be allocated every time

This commit is contained in:
Al
2017-04-04 20:40:55 -04:00
parent 67157fbd98
commit 8742574257
4 changed files with 25 additions and 11 deletions

View File

@@ -287,6 +287,11 @@ bool address_parser_load(char *dir) {
fclose(postal_codes_file);
parser->context = address_parser_context_new();
if (parser->context == NULL) {
goto exit_address_parser_created;
}
char_array_destroy(path);
return true;
@@ -305,6 +310,10 @@ void address_parser_destroy(address_parser_t *self) {
crf_destroy(self->model.crf);
}
if (self->context != NULL) {
address_parser_context_destroy(self->context);
}
if (self->vocab != NULL) {
trie_destroy(self->vocab);
}
@@ -1642,15 +1651,17 @@ libpostal_address_parser_response_t *address_parser_response_new(void) {
return response;
}
libpostal_address_parser_response_t *address_parser_parse(char *address, char *language, char *country, address_parser_context_t *context) {
if (address == NULL || context == NULL) return NULL;
libpostal_address_parser_response_t *address_parser_parse(char *address, char *language, char *country) {
if (address == NULL) return NULL;
address_parser_t *parser = get_address_parser();
if (parser == NULL) {
if (parser == NULL || parser->context == NULL) {
log_error("parser is not setup, call libpostal_setup_address_parser()\n");
return NULL;
}
address_parser_context_t *context = parser->context;
char *normalized = address_parser_normalize_string(address);
bool is_normalized = normalized != NULL;
if (!is_normalized) {