diff --git a/src/source.re.c b/src/source.re.c index ae24589..c613b67 100644 --- a/src/source.re.c +++ b/src/source.re.c @@ -50,7 +50,7 @@ static int source_compare(const union line64 a, const union line64 b) #define TREE_VALUE size_t /* Index into source list. */ #define TREE_COMPARE #define TREE_TO_STRING -#define TREE_DEFAULT (size_t)0 +#define TREE_DEFAULT 0 #include "../src/tree.h" @@ -173,10 +173,13 @@ finally: /** Lookup the last source in `range` in sources `s`. They are invalidated on adding a source, (probably fine.) */ const struct source *source_lookup(struct sources *const s, - const union line64 range) { - union line64 line_source; + const union line64 x) { + struct source_tree_iterator it; assert(s); - line_source = source_tree_less_or(&s->dates, range, (union line64){0}); - sourcemap_table_get(&s->map, line_source); - return s->list.data + idx; + it = source_tree_less(&s->dates, x); + /* If it's before all elements of the journal or is not on the same date as + the source, this has no source, which is `list[0]` by . */ + if(!source_tree_has_element(&it) + || x.date.u32 != source_tree_key(&it).date.u32) return s->list.data + 0; + return s->list.data + *source_tree_value(&it); }