summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/pgf.c
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-10-09 08:38:55 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-10-09 08:38:55 +0000
commit6c86e7fa91602e4863c95622934d45e383890156 (patch)
tree6f8e65171ecf5084e9a9b9c54fbcab60b29b3e2f /src/runtime/c/pgf/pgf.c
parent84b257e85ca15b36e897df8701f66c57064fde97 (diff)
replace the hash maps in the abstract syntax with binary search tables
Diffstat (limited to 'src/runtime/c/pgf/pgf.c')
-rw-r--r--src/runtime/c/pgf/pgf.c89
1 files changed, 48 insertions, 41 deletions
diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c
index 60e838e84..875c65903 100644
--- a/src/runtime/c/pgf/pgf.c
+++ b/src/runtime/c/pgf/pgf.c
@@ -42,15 +42,21 @@ pgf_abstract_name(PgfPGF* pgf)
}
void
-pgf_iter_languages(PgfPGF* pgf, GuMapItor* fn, GuExn* err)
-{
- gu_map_iter(pgf->concretes, fn, err);
+pgf_iter_languages(PgfPGF* pgf, GuMapItor* itor, GuExn* err)
+{
+ size_t n_concrs = gu_seq_length(pgf->concretes);
+ for (size_t i = 0; i < n_concrs; i++) {
+ PgfConcr* concr = gu_seq_index(pgf->concretes, PgfConcr, i);
+ itor->fn(itor, concr->name, concr, err);
+ if (!gu_ok(err))
+ break;
+ }
}
PgfConcr*
pgf_get_language(PgfPGF* pgf, PgfCId lang)
{
- return gu_map_get(pgf->concretes, lang, PgfConcr*);
+ return gu_seq_binsearch(pgf->concretes, pgf_concr_order, PgfConcr, lang);
}
GuString
@@ -60,21 +66,27 @@ pgf_concrete_name(PgfConcr* concr)
}
void
-pgf_iter_categories(PgfPGF* pgf, GuMapItor* fn, GuExn* err)
-{
- gu_map_iter(pgf->abstract.cats, fn, err);
+pgf_iter_categories(PgfPGF* pgf, GuMapItor* itor, GuExn* err)
+{
+ size_t n_cats = gu_seq_length(pgf->abstract.cats);
+ for (size_t i = 0; i < n_cats; i++) {
+ PgfAbsCat* cat = gu_seq_index(pgf->abstract.cats, PgfAbsCat, i);
+ itor->fn(itor, cat->name, cat, err);
+ if (!gu_ok(err))
+ break;
+ }
}
PgfCId
pgf_start_cat(PgfPGF* pgf)
{
- PgfLiteral lit =
- gu_map_get(pgf->abstract.aflags, "startcat", PgfLiteral);
+ PgfFlag* flag =
+ gu_seq_binsearch(pgf->abstract.aflags, pgf_flag_order, PgfFlag, "startcat");
- if (gu_variant_is_null(lit))
+ if (flag == NULL)
return "S";
- GuVariantInfo i = gu_variant_open(lit);
+ GuVariantInfo i = gu_variant_open(flag->value);
switch (i.tag) {
case PGF_LITERAL_STR: {
PgfLiteralStr *lstr = (PgfLiteralStr *) i.data;
@@ -88,13 +100,13 @@ pgf_start_cat(PgfPGF* pgf)
GuString
pgf_language_code(PgfConcr* concr)
{
- PgfLiteral lit =
- gu_map_get(concr->cflags, "language", PgfLiteral);
+ PgfFlag* flag =
+ gu_seq_binsearch(concr->cflags, pgf_flag_order, PgfFlag, "language");
- if (gu_variant_is_null(lit))
+ if (flag == NULL)
return "";
- GuVariantInfo i = gu_variant_open(lit);
+ GuVariantInfo i = gu_variant_open(flag->value);
switch (i.tag) {
case PGF_LITERAL_STR: {
PgfLiteralStr *lstr = (PgfLiteralStr *) i.data;
@@ -106,43 +118,38 @@ pgf_language_code(PgfConcr* concr)
}
void
-pgf_iter_functions(PgfPGF* pgf, GuMapItor* fn, GuExn* err)
-{
- gu_map_iter(pgf->abstract.funs, fn, err);
-}
-
-typedef struct {
- GuMapItor fn;
- PgfCId catname;
- GuMapItor* client_fn;
-} PgfFunByCatIter;
-
-static void
-pgf_filter_by_cat(GuMapItor* fn, const void* key, void* value, GuExn* err)
-{
- (void) (key && err);
-
- PgfFunByCatIter* clo = (PgfFunByCatIter*) fn;
- PgfAbsFun* absfun = *((PgfAbsFun**) value);
-
- if (strcmp(absfun->type->cid, clo->catname) == 0) {
- clo->client_fn->fn(clo->client_fn, absfun->name, NULL, err);
+pgf_iter_functions(PgfPGF* pgf, GuMapItor* itor, GuExn* err)
+{
+ size_t n_funs = gu_seq_length(pgf->abstract.funs);
+ for (size_t i = 0; i < n_funs; i++) {
+ PgfAbsFun* fun = gu_seq_index(pgf->abstract.funs, PgfAbsFun, i);
+ itor->fn(itor, fun->name, fun, err);
+ if (!gu_ok(err))
+ break;
}
}
void
pgf_iter_functions_by_cat(PgfPGF* pgf, PgfCId catname,
- GuMapItor* fn, GuExn* err)
-{
- PgfFunByCatIter clo = { { pgf_filter_by_cat }, catname, fn };
- gu_map_iter(pgf->abstract.funs, &clo.fn, err);
+ GuMapItor* itor, GuExn* err)
+{
+ size_t n_funs = gu_seq_length(pgf->abstract.funs);
+ for (size_t i = 0; i < n_funs; i++) {
+ PgfAbsFun* fun = gu_seq_index(pgf->abstract.funs, PgfAbsFun, i);
+
+ if (strcmp(fun->type->cid, catname) == 0) {
+ itor->fn(itor, fun->name, fun, err);
+ if (!gu_ok(err))
+ break;
+ }
+ }
}
PgfType*
pgf_function_type(PgfPGF* pgf, PgfCId funname)
{
PgfAbsFun* absfun =
- gu_map_get(pgf->abstract.funs, funname, PgfAbsFun*);
+ gu_seq_binsearch(pgf->abstract.funs, pgf_absfun_order, PgfAbsFun, funname);
if (absfun == NULL)
return NULL;