[Github-comments] [geany/geany] TM cleanups (#957)

Colomban Wendling notifications at xxxxx
Tue May 3 20:20:58 UTC 2016


> +
> +
> +TMTagType tm_parser_get_tag_type(gchar kind, TMParserType lang)
> +{
> +	TMParserMap *map = &parser_map[lang];
> +	guint i;
> +
> +	for (i = 0; i < map->size; i++)
> +	{
> +		TMParserMapEntry *entry = &map->entries[i];
> +
> +		if (entry->kind == kind)
> +			return entry->type;
> +	}
> +	return tm_tag_undef_t;
> +}

If type lookup happens to be a bottleneck, we could index on kind letter in the maps:

```c
static TMTagType map_CONF[128] = {
	['n'] = tm_tag_namespace_t,
	['m'] = tm_tag_macro_t,
};
```
it obviously has a memory footprint cost though (`sizeof(TMTagType)*128 - (sizeof(TMParserMapEntry - sizeof(TMTagType)) * n_actual_entries` -- likely about 120*4 = 480 bytes per map, so about 24kb), which may or may not be worth it.  If we weren't afraid, we could lower this to 52 entries tops instead of 128 (so about 9kb) as we can assume kinds are alphabetic letters, so can do something like that:
```c
#define ENTRY(letter, type) \
	[(letter >= 'A' && letter <= 'Z') ? (letter - 'A') : \
	 (letter >= 'a' && letter <= 'z') ? ('Z' + 1 + letter - 'a') : \
	 -1] = type

static TMTagType map_CONF[26*2] = {
	ENTRY('n', tm_tag_namespace_t),
	ENTRY('m', tm_tag_macro_t),
};
```

It could also simply have the kinds sorted alphabetically, too, and use a bsearch.

Anyway, hypothetical problem for now :)

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/957/files/aea7d7845917843dd6b02e5a8dc9031cabc87a86..5d9376ea801a6e6c3ec22748741362a3a2eff7ac#r61948761
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20160503/2d235363/attachment.html>


More information about the Github-comments mailing list