locate: use const pointers

Pass const pointers where no writes are performed.
This commit is contained in:
Max Kellermann 2009-01-22 16:12:34 +01:00
parent d47be76ce0
commit 1e6a26b6ca
4 changed files with 28 additions and 32 deletions

View File

@ -36,12 +36,12 @@
typedef struct _ListCommandItem { typedef struct _ListCommandItem {
int8_t tagType; int8_t tagType;
int numConditionals; int numConditionals;
LocateTagItem *conditionals; const LocateTagItem *conditionals;
} ListCommandItem; } ListCommandItem;
typedef struct _LocateTagItemArray { typedef struct _LocateTagItemArray {
int numItems; int numItems;
LocateTagItem *items; const LocateTagItem *items;
} LocateTagItemArray; } LocateTagItemArray;
typedef struct _SearchStats { typedef struct _SearchStats {
@ -87,31 +87,24 @@ searchInDirectory(struct song *song, void *_data)
} }
int searchForSongsIn(struct client *client, const char *name, int searchForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items) int numItems, const LocateTagItem * items)
{ {
int ret; int ret;
int i; int i;
LocateTagItem *new_items =
char **originalNeedles = g_new(char *, numItems); g_memdup(items, sizeof(LocateTagItem) * numItems);
struct search_data data; struct search_data data;
for (i = 0; i < numItems; i++) { for (i = 0; i < numItems; i++)
originalNeedles[i] = items[i].needle; new_items[i].needle = g_utf8_casefold(new_items[i].needle, -1);
items[i].needle = g_utf8_casefold(originalNeedles[i], -1);
}
data.client = client; data.client = client;
data.array.numItems = numItems; data.array.numItems = numItems;
data.array.items = items; data.array.items = new_items;
ret = db_walk(name, searchInDirectory, NULL, &data); ret = db_walk(name, searchInDirectory, NULL, &data);
for (i = 0; i < numItems; i++) { freeLocateTagItemArray(numItems, new_items);
g_free(items[i].needle);
items[i].needle = originalNeedles[i];
}
free(originalNeedles);
return ret; return ret;
} }
@ -129,7 +122,7 @@ findInDirectory(struct song *song, void *_data)
} }
int findSongsIn(struct client *client, const char *name, int findSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items) int numItems, const LocateTagItem * items)
{ {
struct search_data data; struct search_data data;
@ -162,7 +155,7 @@ searchStatsInDirectory(struct song *song, void *data)
} }
int searchStatsForSongsIn(struct client *client, const char *name, int searchStatsForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items) int numItems, const LocateTagItem * items)
{ {
SearchStats stats; SearchStats stats;
int ret; int ret;
@ -234,7 +227,7 @@ int printInfoForAllIn(struct client *client, const char *name)
} }
static ListCommandItem *newListCommandItem(int tagType, int numConditionals, static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
LocateTagItem * conditionals) const LocateTagItem * conditionals)
{ {
ListCommandItem *item = g_new(ListCommandItem, 1); ListCommandItem *item = g_new(ListCommandItem, 1);
@ -295,7 +288,7 @@ listUniqueTagsInDirectory(struct song *song, void *_data)
} }
int listAllUniqueTags(struct client *client, int type, int numConditionals, int listAllUniqueTags(struct client *client, int type, int numConditionals,
LocateTagItem * conditionals) const LocateTagItem *conditionals)
{ {
int ret; int ret;
ListCommandItem *item = newListCommandItem(type, numConditionals, ListCommandItem *item = newListCommandItem(type, numConditionals,

View File

@ -32,18 +32,18 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file);
int printInfoForAllIn(struct client *client, const char *name); int printInfoForAllIn(struct client *client, const char *name);
int searchForSongsIn(struct client *client, const char *name, int searchForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items); int numItems, const LocateTagItem * items);
int findSongsIn(struct client *client, const char *name, int findSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items); int numItems, const LocateTagItem * items);
int searchStatsForSongsIn(struct client *client, const char *name, int searchStatsForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items); int numItems, const LocateTagItem * items);
unsigned long sumSongTimesIn(const char *name); unsigned long sumSongTimesIn(const char *name);
int listAllUniqueTags(struct client *client, int type, int numConditiionals, int listAllUniqueTags(struct client *client, int type, int numConditiionals,
LocateTagItem * conditionals); const LocateTagItem *conditionals);
void printSavedMemoryFromFilenames(void); void printSavedMemoryFromFilenames(void);

View File

@ -127,7 +127,7 @@ void freeLocateTagItem(LocateTagItem * item)
} }
static int static int
strstrSearchTag(struct song *song, enum tag_type type, char *str) strstrSearchTag(const struct song *song, enum tag_type type, const char *str)
{ {
int i; int i;
char *duplicate; char *duplicate;
@ -177,7 +177,8 @@ strstrSearchTag(struct song *song, enum tag_type type, char *str)
} }
int int
strstrSearchTags(struct song *song, int numItems, LocateTagItem *items) strstrSearchTags(const struct song *song, int numItems,
const LocateTagItem *items)
{ {
int i; int i;
@ -192,7 +193,8 @@ strstrSearchTags(struct song *song, int numItems, LocateTagItem *items)
} }
static int static int
tagItemFoundAndMatches(struct song *song, enum tag_type type, char *str) tagItemFoundAndMatches(const struct song *song, enum tag_type type,
const char *str)
{ {
int i; int i;
int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 }; int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
@ -237,8 +239,8 @@ tagItemFoundAndMatches(struct song *song, enum tag_type type, char *str)
int int
tagItemsFoundAndMatches(struct song *song, int numItems, tagItemsFoundAndMatches(const struct song *song, int numItems,
LocateTagItem * items) const LocateTagItem * items)
{ {
int i; int i;

View File

@ -47,10 +47,11 @@ void freeLocateTagItemArray(int count, LocateTagItem * array);
void freeLocateTagItem(LocateTagItem * item); void freeLocateTagItem(LocateTagItem * item);
int int
strstrSearchTags(struct song *song, int numItems, LocateTagItem * items); strstrSearchTags(const struct song *song, int numItems,
const LocateTagItem * items);
int int
tagItemsFoundAndMatches(struct song *song, int numItems, tagItemsFoundAndMatches(const struct song *song, int numItems,
LocateTagItem * items); const LocateTagItem * items);
#endif #endif