Skip to content

Commit 0d9af06

Browse files
avargitster
authored andcommitted
streaming.c: remove enum/function/vtbl indirection
Remove the indirection of discovering a function pointer to use via an enum and virtual table. This refactors code added in 46bf043 (streaming: a new API to read from the object store, 2011-05-11). We can instead simply return an "open_istream_fn" for use from the "istream_source()" selector function directly. This allows us to get rid of the "incore", "loose" and "pack_non_delta" enum variables. We'll return the functions instead. The "stream_error" variable in that enum can likewise go in favor of returning NULL, which is what the open_istream() was doing when it got that value anyway. We can thus remove the entire enum, and the "open_istream_tbl" virtual table that (indirectly) referenced it. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b655283 commit 0d9af06

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

streaming.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
#include "replace-object.h"
99
#include "packfile.h"
1010

11-
enum input_source {
12-
stream_error = -1,
13-
incore = 0,
14-
loose = 1,
15-
pack_non_delta = 2
16-
};
17-
1811
typedef int (*open_istream_fn)(struct git_istream *,
1912
struct repository *,
2013
struct object_info *,
@@ -424,16 +417,10 @@ static open_method_decl(incore)
424417
* static helpers variables and functions for users of streaming interface
425418
*****************************************************************************/
426419

427-
static open_istream_fn open_istream_tbl[] = {
428-
open_istream_incore,
429-
open_istream_loose,
430-
open_istream_pack_non_delta,
431-
};
432-
433-
static enum input_source istream_source(struct repository *r,
434-
const struct object_id *oid,
435-
enum object_type *type,
436-
struct object_info *oi)
420+
static open_istream_fn istream_source(struct repository *r,
421+
const struct object_id *oid,
422+
enum object_type *type,
423+
struct object_info *oi)
437424
{
438425
unsigned long size;
439426
int status;
@@ -442,21 +429,20 @@ static enum input_source istream_source(struct repository *r,
442429
oi->sizep = &size;
443430
status = oid_object_info_extended(r, oid, oi, 0);
444431
if (status < 0)
445-
return stream_error;
432+
return NULL;
446433

447434
switch (oi->whence) {
448435
case OI_LOOSE:
449-
return loose;
436+
return open_istream_loose;
450437
case OI_PACKED:
451438
if (!oi->u.packed.is_delta && big_file_threshold < size)
452-
return pack_non_delta;
439+
return open_istream_pack_non_delta;
453440
/* fallthru */
454441
default:
455-
return incore;
442+
return open_istream_incore;
456443
}
457444
}
458445

459-
460446
/****************************************************************
461447
* Users of streaming interface
462448
****************************************************************/
@@ -482,13 +468,13 @@ struct git_istream *open_istream(struct repository *r,
482468
struct git_istream *st;
483469
struct object_info oi = OBJECT_INFO_INIT;
484470
const struct object_id *real = lookup_replace_object(r, oid);
485-
enum input_source src = istream_source(r, real, type, &oi);
471+
open_istream_fn open_fn = istream_source(r, real, type, &oi);
486472

487-
if (src < 0)
473+
if (!open_fn)
488474
return NULL;
489475

490476
st = xmalloc(sizeof(*st));
491-
if (open_istream_tbl[src](st, r, &oi, real, type)) {
477+
if (open_fn(st, r, &oi, real, type)) {
492478
if (open_istream_incore(st, r, &oi, real, type)) {
493479
free(st);
494480
return NULL;

0 commit comments

Comments
 (0)