diff --git a/src/ChangeLog b/src/ChangeLog index afde3720c..37257a7b7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2005-07-07 Roland Illig + + * view.c (view_ccache_find): Replaced the linear search with a + binary search. This speeds up the viewer by a factor of 25 for + large files (> 100 MB). + 2005-07-07 Roland Illig * dialog.h: Replaced object-like macros with implicit references diff --git a/src/view.c b/src/view.c index 6cd3fe546..f364b14aa 100644 --- a/src/view.c +++ b/src/view.c @@ -810,34 +810,7 @@ is_nroff_sequence (WView *view, offset_type offset) } 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; -} - -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; - assert (i != 0); - do { - i--; - } while (coord_cache_entry_less (coord, &cache[i], sort_by, view->text_nroff_mode)); - return i; -} - -static inline guint -view_ccache_find_binary (WView *view, const struct coord_cache_entry *cache, +view_ccache_find (WView *view, const struct coord_cache_entry *cache, const struct coord_cache_entry *coord, enum ccache_type sort_by) { guint base, i, limit; @@ -859,21 +832,6 @@ view_ccache_find_binary (WView *view, const struct coord_cache_entry *cache, return base; } -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) -{ - volatile guint linear_down, linear_up, binary; - - linear_down = view_ccache_find_linear_down (view, cache, coord, sort_by); - linear_up = view_ccache_find_linear_up (view, cache, coord, sort_by); - binary = view_ccache_find_binary (view, cache, coord, sort_by); - - assert (linear_down == linear_up); - assert (linear_down == binary); - return binary; -} - /* 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''.