Skip to content

Commit

Permalink
readtags,refactor: lift the code running Sorter up to the caller side
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Sep 12, 2024
1 parent 11d0ffb commit 044cd45
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions extra-cmds/readtags-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ struct actionSpec {
const char *name; /* for ACTION_FIND */
bool canonicalizing;
struct canonWorkArea canon;
ptrArray *tagEntryArray;
void (* walkerfn) (const tagEntry *, void *);
void *dataForWalkerFn;
};

static const char *ProgramName;
Expand Down Expand Up @@ -179,10 +182,7 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
void (* actionfn) (const tagEntry *, void *), void *data,
struct actionSpec *actionSpec)
{
ptrArray *a = NULL;

if (Sorter)
a = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);
ptrArray *a = actionSpec->tagEntryArray;

do
{
Expand Down Expand Up @@ -230,14 +230,8 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,

if (a)
{
ptrArraySort (a, compareTagEntry);
unsigned int count = ptrArrayCount (a);
for (unsigned int i = 0; i < count; i++)
{
tagEntry *e = ptrArrayItem (a, i);
(* actionfn) (e, data);
}
ptrArrayDelete (a);
actionSpec->walkerfn = actionfn;
actionSpec->dataForWalkerFn = data;
}
}
#else
Expand Down Expand Up @@ -687,6 +681,9 @@ extern int main (int argc, char **argv)
.ptags = false,
/* .absoluteOnly = false, */
},
.tagEntryArray = NULL,
.walkerfn = NULL,
.dataForWalkerFn = NULL,
};

ProgramName = argv [0];
Expand Down Expand Up @@ -967,6 +964,11 @@ extern int main (int argc, char **argv)
exit (1);

Check warning on line 964 in extra-cmds/readtags-cmd.c

View check run for this annotation

Codecov / codecov/patch

extra-cmds/readtags-cmd.c#L964

Added line #L964 was not covered by tests
}

#ifdef READTAGS_DSL
if (Sorter)
actionSpec.tagEntryArray = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);
#endif

if (actionSpec.action & ACTION_LIST_PTAGS)
{
if (actionSpec.canonicalizing)
Expand All @@ -981,6 +983,22 @@ extern int main (int argc, char **argv)
else if (actionSpec.action & ACTION_LIST)
listTags (&inputSpec, false, &printOpts, &actionSpec);

if (actionSpec.tagEntryArray)
{
#ifdef READTAGS_DSL
if (Sorter)
ptrArraySort (actionSpec.tagEntryArray, compareTagEntry);
#endif

const size_t entry_count = ptrArrayCount(actionSpec.tagEntryArray);
for (unsigned int i = 0; i < entry_count; i++)
{
tagEntry *e = ptrArrayItem (actionSpec.tagEntryArray, i);
actionSpec.walkerfn (e, actionSpec.dataForWalkerFn);
}
ptrArrayDelete (actionSpec.tagEntryArray);
}

#ifdef READTAGS_DSL
if (Qualifier)
q_destroy (Qualifier);
Expand Down

0 comments on commit 044cd45

Please sign in to comment.