diff --git a/src/view.c b/src/view.c index da35fde01..96ec1da2c 100644 --- a/src/view.c +++ b/src/view.c @@ -809,6 +809,64 @@ is_nroff_sequence (WView *view, offset_type offset) return (c0 == c2 || c0 == '_' || (c0 == '+' && c2 == 'o')); } +#define MCVIEW_USE_FIND_LINEAR_DOWN + +#ifdef MCVIEW_USE_FIND_LINEAR_DOWN +static inline guint +view_ccache_find_linear_down (WView *view, const struct coord_cache_entry *cache, + const struct coord_cache_entry *coord, enum ccache_type sort_by) +{ + guint i; + + for (i = 0; i + 1 < view->coord_cache->len; i++) { + if (coord_cache_entry_less (coord, &(cache[i + 1]), sort_by, view->text_nroff_mode)) + break; + } + return i; +} +#endif + +#ifdef MCVIEW_USE_FIND_LINEAR_UP +static inline guint +view_ccache_find_linear_up (WView *view, const struct coord_cache_entry *cache, + const struct coord_cache_entry *coord, enum ccache_type sort_by) +{ + guint i; + + i = view->coord_cache->len; + if (i != 0) { + do { + i--; + } while (coord_cache_entry_less (coord, &cache[i], sort_by, view->text_nroff_mode)); + } + return i; +} +#endif + +#ifdef MCVIEW_USE_FIND_BINARY +static inline guint +view_ccache_find_binary (WView *view, const struct coord_cache_entry *cache, + const struct coord_cache_entry *coord, enum ccache_type sort_by) +{ + abort(); /* does not work yet */ +} +#endif + +static inline guint +view_ccache_find (WView *view, const struct coord_cache_entry *cache, + const struct coord_cache_entry *coord, enum ccache_type sort_by) +{ +#if defined(MCVIEW_USE_FIND_LINEAR_DOWN) + return view_ccache_find_linear_down (view, cache, coord, sort_by); +#elif defined(MCVIEW_USE_FIND_LINEAR_UP) + return view_ccache_find_linear_up (view, cache, coord, sort_by); +#elif defined(MCVIEW_USE_FIND_BINARY) + return view_ccache_find_binary (view, cache, coord, sort_by); +#else +# error No find function defined. +#endif +} + /* Look up the missing components of ''coord'', which are given by * ''lookup_what''. The function returns the smallest value that * matches the existing components of ''coord''. @@ -841,10 +899,7 @@ view_ccache_lookup (WView *view, struct coord_cache_entry *coord, retry: /* find the two neighbor entries in the cache */ cache = &(g_array_index (view->coord_cache, struct coord_cache_entry, 0)); - for (i = 0; i + 1 < view->coord_cache->len; i++) { - if (coord_cache_entry_less (coord, &(cache[i + 1]), sorter, view->text_nroff_mode)) - break; - } + i = view_ccache_find (view, cache, coord, sorter); /* now i points to the lower neighbor in the cache */ current = cache[i];