aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-22 16:12:34 +0100
committerMax Kellermann <max@duempel.org>2009-01-22 16:12:34 +0100
commit1e6a26b6cae1e9bd90d820c6ea4ec8be2da2da91 (patch)
treedeb75a9e6ea111728571f99357c69d05697531dc /src
parentd47be76ce09ab3de9dfd5989ea65ca305c723f73 (diff)
downloadmpd-1e6a26b6cae1e9bd90d820c6ea4ec8be2da2da91.tar.gz
mpd-1e6a26b6cae1e9bd90d820c6ea4ec8be2da2da91.tar.xz
mpd-1e6a26b6cae1e9bd90d820c6ea4ec8be2da2da91.zip
locate: use const pointers
Pass const pointers where no writes are performed.
Diffstat (limited to 'src')
-rw-r--r--src/dbUtils.c33
-rw-r--r--src/dbUtils.h8
-rw-r--r--src/locate.c12
-rw-r--r--src/locate.h7
4 files changed, 28 insertions, 32 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c
index cd1476d9d..709bca120 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -36,12 +36,12 @@
typedef struct _ListCommandItem {
int8_t tagType;
int numConditionals;
- LocateTagItem *conditionals;
+ const LocateTagItem *conditionals;
} ListCommandItem;
typedef struct _LocateTagItemArray {
int numItems;
- LocateTagItem *items;
+ const LocateTagItem *items;
} LocateTagItemArray;
typedef struct _SearchStats {
@@ -87,31 +87,24 @@ searchInDirectory(struct song *song, void *_data)
}
int searchForSongsIn(struct client *client, const char *name,
- int numItems, LocateTagItem * items)
+ int numItems, const LocateTagItem * items)
{
int ret;
int i;
-
- char **originalNeedles = g_new(char *, numItems);
+ LocateTagItem *new_items =
+ g_memdup(items, sizeof(LocateTagItem) * numItems);
struct search_data data;
- for (i = 0; i < numItems; i++) {
- originalNeedles[i] = items[i].needle;
- items[i].needle = g_utf8_casefold(originalNeedles[i], -1);
- }
+ for (i = 0; i < numItems; i++)
+ new_items[i].needle = g_utf8_casefold(new_items[i].needle, -1);
data.client = client;
data.array.numItems = numItems;
- data.array.items = items;
+ data.array.items = new_items;
ret = db_walk(name, searchInDirectory, NULL, &data);
- for (i = 0; i < numItems; i++) {
- g_free(items[i].needle);
- items[i].needle = originalNeedles[i];
- }
-
- free(originalNeedles);
+ freeLocateTagItemArray(numItems, new_items);
return ret;
}
@@ -129,7 +122,7 @@ findInDirectory(struct song *song, void *_data)
}
int findSongsIn(struct client *client, const char *name,
- int numItems, LocateTagItem * items)
+ int numItems, const LocateTagItem * items)
{
struct search_data data;
@@ -162,7 +155,7 @@ searchStatsInDirectory(struct song *song, void *data)
}
int searchStatsForSongsIn(struct client *client, const char *name,
- int numItems, LocateTagItem * items)
+ int numItems, const LocateTagItem * items)
{
SearchStats stats;
int ret;
@@ -234,7 +227,7 @@ int printInfoForAllIn(struct client *client, const char *name)
}
static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
- LocateTagItem * conditionals)
+ const LocateTagItem * conditionals)
{
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,
- LocateTagItem * conditionals)
+ const LocateTagItem *conditionals)
{
int ret;
ListCommandItem *item = newListCommandItem(type, numConditionals,
diff --git a/src/dbUtils.h b/src/dbUtils.h
index 5c8e71604..c7302a1b2 100644
--- a/src/dbUtils.h
+++ b/src/dbUtils.h
@@ -32,18 +32,18 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file);
int printInfoForAllIn(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 numItems, LocateTagItem * items);
+ int numItems, const LocateTagItem * items);
int searchStatsForSongsIn(struct client *client, const char *name,
- int numItems, LocateTagItem * items);
+ int numItems, const LocateTagItem * items);
unsigned long sumSongTimesIn(const char *name);
int listAllUniqueTags(struct client *client, int type, int numConditiionals,
- LocateTagItem * conditionals);
+ const LocateTagItem *conditionals);
void printSavedMemoryFromFilenames(void);
diff --git a/src/locate.c b/src/locate.c
index cd26dbd68..a7804ea49 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -127,7 +127,7 @@ void freeLocateTagItem(LocateTagItem * item)
}
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;
char *duplicate;
@@ -177,7 +177,8 @@ strstrSearchTag(struct song *song, enum tag_type type, char *str)
}
int
-strstrSearchTags(struct song *song, int numItems, LocateTagItem *items)
+strstrSearchTags(const struct song *song, int numItems,
+ const LocateTagItem *items)
{
int i;
@@ -192,7 +193,8 @@ strstrSearchTags(struct song *song, int numItems, LocateTagItem *items)
}
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;
int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
@@ -237,8 +239,8 @@ tagItemFoundAndMatches(struct song *song, enum tag_type type, char *str)
int
-tagItemsFoundAndMatches(struct song *song, int numItems,
- LocateTagItem * items)
+tagItemsFoundAndMatches(const struct song *song, int numItems,
+ const LocateTagItem * items)
{
int i;
diff --git a/src/locate.h b/src/locate.h
index 1e57686de..fbcc8831d 100644
--- a/src/locate.h
+++ b/src/locate.h
@@ -47,10 +47,11 @@ void freeLocateTagItemArray(int count, LocateTagItem * array);
void freeLocateTagItem(LocateTagItem * item);
int
-strstrSearchTags(struct song *song, int numItems, LocateTagItem * items);
+strstrSearchTags(const struct song *song, int numItems,
+ const LocateTagItem * items);
int
-tagItemsFoundAndMatches(struct song *song, int numItems,
- LocateTagItem * items);
+tagItemsFoundAndMatches(const struct song *song, int numItems,
+ const LocateTagItem * items);
#endif