From: Patrick Steinhardt Date: Thu, 09 Apr 2026 10:41:33 GMT Subject: Re: [PATCH v2 01/17] odb: introduce "in-memory" source Message-ID: In-Reply-To: On Thu, Apr 09, 2026 at 05:26:50AM -0400, Karthik Nayak wrote: > > diff --git a/odb/source-inmemory.h b/odb/source-inmemory.h > > new file mode 100644 > > index 0000000000..95477bf36d > > --- /dev/null > > +++ b/odb/source-inmemory.h > > @@ -0,0 +1,35 @@ > > +#ifndef ODB_SOURCE_INMEMORY_H > > +#define ODB_SOURCE_INMEMORY_H > > + > > +#include "odb/source.h" > > + > > +struct cached_object_entry; > > + > > +/* > > + * An inmemory source that you can write objects to that shall be made > > + * available for reading, but that shouldn't ever be persisted to disk. Note > > + * that any objects written to this source will be stored in memory, so the > > + * number of objects you can store is limited by available system memory. > > + */ > > +struct odb_source_inmemory { > > + struct odb_source base; > > + > > + struct cached_object_entry *objects; > > + size_t objects_nr, objects_alloc; > > +}; > > + > > +/* Create a new in-memory object database source. */ > > +struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb); > > + > > +/* > > + * Cast the given object database source to the inmemory backend. This will > > + * cause a BUG in case the source doesn't use this backend. > > + */ > > +static inline struct odb_source_inmemory *odb_source_inmemory_downcast(struct odb_source *source) > > +{ > > + if (source->type != ODB_SOURCE_INMEMORY) > > + BUG("trying to downcast source of type '%d' to inmemory", source->type); > > + return container_of(source, struct odb_source_inmemory, base); > > +} > > + > > Interesting, in the refs namespace the downcast functions are added to > the source file (.c). This works too, is there any reason though? By having it static inline over here we can basically ensure that the compiler can inline this call everywhere. I doubt that it really matters in the end, but I guess it doesn't hurt, either. Patrick