mirror of
https://github.com/git-for-windows/git.git
synced 2026-04-11 01:53:21 -05:00
The in-memory source stores its objects in a simple array that we grow as
needed. This has a couple of downsides:
- The object lookup is O(n). This doesn't matter in practice because
we only store a small number of objects.
- We don't have an easy way to iterate over all objects in
lexicographic order.
- We don't have an easy way to compute unique object ID prefixes.
Refactor the code to use an oidtree instead. This is the same data
structure used by our loose object source, and thus it means we get a
bunch of functionality for free.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
34 lines
1.0 KiB
C
34 lines
1.0 KiB
C
#ifndef ODB_SOURCE_INMEMORY_H
|
|
#define ODB_SOURCE_INMEMORY_H
|
|
|
|
#include "odb/source.h"
|
|
|
|
struct oidtree;
|
|
|
|
/*
|
|
* 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 oidtree *objects;
|
|
};
|
|
|
|
/* 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);
|
|
}
|
|
|
|
#endif
|