Skip to content

Commit 044cd45

Browse files
committed
readtags,refactor: lift the code running Sorter up to the caller side
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 11d0ffb commit 044cd45

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

Diff for: extra-cmds/readtags-cmd.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ struct actionSpec {
6060
const char *name; /* for ACTION_FIND */
6161
bool canonicalizing;
6262
struct canonWorkArea canon;
63+
ptrArray *tagEntryArray;
64+
void (* walkerfn) (const tagEntry *, void *);
65+
void *dataForWalkerFn;
6366
};
6467

6568
static const char *ProgramName;
@@ -179,10 +182,7 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
179182
void (* actionfn) (const tagEntry *, void *), void *data,
180183
struct actionSpec *actionSpec)
181184
{
182-
ptrArray *a = NULL;
183-
184-
if (Sorter)
185-
a = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);
185+
ptrArray *a = actionSpec->tagEntryArray;
186186

187187
do
188188
{
@@ -230,14 +230,8 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
230230

231231
if (a)
232232
{
233-
ptrArraySort (a, compareTagEntry);
234-
unsigned int count = ptrArrayCount (a);
235-
for (unsigned int i = 0; i < count; i++)
236-
{
237-
tagEntry *e = ptrArrayItem (a, i);
238-
(* actionfn) (e, data);
239-
}
240-
ptrArrayDelete (a);
233+
actionSpec->walkerfn = actionfn;
234+
actionSpec->dataForWalkerFn = data;
241235
}
242236
}
243237
#else
@@ -687,6 +681,9 @@ extern int main (int argc, char **argv)
687681
.ptags = false,
688682
/* .absoluteOnly = false, */
689683
},
684+
.tagEntryArray = NULL,
685+
.walkerfn = NULL,
686+
.dataForWalkerFn = NULL,
690687
};
691688

692689
ProgramName = argv [0];
@@ -967,6 +964,11 @@ extern int main (int argc, char **argv)
967964
exit (1);
968965
}
969966

967+
#ifdef READTAGS_DSL
968+
if (Sorter)
969+
actionSpec.tagEntryArray = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);
970+
#endif
971+
970972
if (actionSpec.action & ACTION_LIST_PTAGS)
971973
{
972974
if (actionSpec.canonicalizing)
@@ -981,6 +983,22 @@ extern int main (int argc, char **argv)
981983
else if (actionSpec.action & ACTION_LIST)
982984
listTags (&inputSpec, false, &printOpts, &actionSpec);
983985

986+
if (actionSpec.tagEntryArray)
987+
{
988+
#ifdef READTAGS_DSL
989+
if (Sorter)
990+
ptrArraySort (actionSpec.tagEntryArray, compareTagEntry);
991+
#endif
992+
993+
const size_t entry_count = ptrArrayCount(actionSpec.tagEntryArray);
994+
for (unsigned int i = 0; i < entry_count; i++)
995+
{
996+
tagEntry *e = ptrArrayItem (actionSpec.tagEntryArray, i);
997+
actionSpec.walkerfn (e, actionSpec.dataForWalkerFn);
998+
}
999+
ptrArrayDelete (actionSpec.tagEntryArray);
1000+
}
1001+
9841002
#ifdef READTAGS_DSL
9851003
if (Qualifier)
9861004
q_destroy (Qualifier);

0 commit comments

Comments
 (0)