Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d2cf7402
Commit
d2cf7402
authored
Jan 18, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Song: embed the Tag object statically into class Song
Reduces overhead because we need to manage only one memory allocation. According to valgrind/massif, we save 7%.
parent
bc966577
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
26 additions
and
47 deletions
+26
-47
DatabaseHelpers.cxx
src/DatabaseHelpers.cxx
+2
-5
DatabasePrint.cxx
src/DatabasePrint.cxx
+2
-2
DetachedSong.cxx
src/DetachedSong.cxx
+1
-1
PlaylistUpdate.cxx
src/PlaylistUpdate.cxx
+1
-3
Song.cxx
src/Song.cxx
+4
-5
Song.hxx
src/Song.hxx
+2
-2
SongFilter.cxx
src/SongFilter.cxx
+1
-1
SongPrint.cxx
src/SongPrint.cxx
+1
-2
SongSave.cxx
src/SongSave.cxx
+1
-2
SongSort.cxx
src/SongSort.cxx
+6
-14
SongUpdate.cxx
src/SongUpdate.cxx
+2
-4
UpdateContainer.cxx
src/UpdateContainer.cxx
+1
-4
ProxyDatabasePlugin.cxx
src/db/ProxyDatabasePlugin.cxx
+1
-1
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+1
-1
No files found.
src/DatabaseHelpers.cxx
View file @
d2cf7402
...
...
@@ -39,9 +39,7 @@ typedef std::set<const char *, StringLess> StringSet;
static
bool
CollectTags
(
StringSet
&
set
,
TagType
tag_type
,
Song
&
song
)
{
Tag
*
tag
=
song
.
tag
;
if
(
tag
==
nullptr
)
return
true
;
const
Tag
*
tag
=
&
song
.
tag
;
bool
found
=
false
;
for
(
unsigned
i
=
0
;
i
<
tag
->
num_items
;
++
i
)
{
...
...
@@ -108,8 +106,7 @@ StatsVisitSong(DatabaseStats &stats, StringSet &artists, StringSet &albums,
{
++
stats
.
song_count
;
if
(
song
.
tag
!=
nullptr
)
StatsVisitTag
(
stats
,
artists
,
albums
,
*
song
.
tag
);
StatsVisitTag
(
stats
,
artists
,
albums
,
song
.
tag
);
return
true
;
}
...
...
src/DatabasePrint.cxx
View file @
d2cf7402
...
...
@@ -70,7 +70,7 @@ PrintSongBrief(Client &client, const Song &song)
{
song_print_uri
(
client
,
song
);
if
(
song
.
tag
!=
nullptr
&&
song
.
tag
->
has_playlist
)
if
(
song
.
tag
.
has_playlist
)
/* this song file has an embedded CUE sheet */
print_playlist_in_directory
(
client
,
song
.
parent
,
song
.
uri
);
...
...
@@ -82,7 +82,7 @@ PrintSongFull(Client &client, const Song &song)
{
song_print_info
(
client
,
song
);
if
(
song
.
tag
!=
nullptr
&&
song
.
tag
->
has_playlist
)
if
(
song
.
tag
.
has_playlist
)
/* this song file has an embedded CUE sheet */
print_playlist_in_directory
(
client
,
song
.
parent
,
song
.
uri
);
...
...
src/DetachedSong.cxx
View file @
d2cf7402
...
...
@@ -25,7 +25,7 @@
DetachedSong
::
DetachedSong
(
const
Song
&
other
)
:
uri
(
other
.
GetURI
().
c_str
()),
tag
(
other
.
tag
!=
nullptr
?
*
other
.
tag
:
Tag
()
),
tag
(
other
.
tag
),
mtime
(
other
.
mtime
),
start_ms
(
other
.
start_ms
),
end_ms
(
other
.
end_ms
)
{}
...
...
src/PlaylistUpdate.cxx
View file @
d2cf7402
...
...
@@ -49,9 +49,7 @@ UpdatePlaylistSong(const Database &db, DetachedSong &song)
}
song
.
SetLastModified
(
original
->
mtime
);
if
(
original
->
tag
!=
nullptr
)
song
.
SetTag
(
*
original
->
tag
);
song
.
SetTag
(
original
->
tag
);
db
.
ReturnSong
(
original
);
return
true
;
...
...
src/Song.cxx
View file @
d2cf7402
...
...
@@ -29,14 +29,13 @@
#include <stdlib.h>
inline
Song
::
Song
(
const
char
*
_uri
,
size_t
uri_length
,
Directory
*
_parent
)
:
tag
(
nullptr
),
parent
(
_parent
),
mtime
(
0
),
start_ms
(
0
),
end_ms
(
0
)
:
parent
(
_parent
),
mtime
(
0
),
start_ms
(
0
),
end_ms
(
0
)
{
memcpy
(
uri
,
_uri
,
uri_length
+
1
);
}
inline
Song
::~
Song
()
{
delete
tag
;
}
static
Song
*
...
...
@@ -57,7 +56,7 @@ Song *
Song
::
NewFrom
(
DetachedSong
&&
other
,
Directory
*
parent
)
{
Song
*
song
=
song_alloc
(
other
.
GetURI
(),
parent
);
song
->
tag
=
new
Tag
(
std
::
move
(
other
.
WritableTag
()
));
song
->
tag
=
std
::
move
(
other
.
WritableTag
(
));
song
->
mtime
=
other
.
GetLastModified
();
song
->
start_ms
=
other
.
GetStartMS
();
song
->
end_ms
=
other
.
GetEndMS
();
...
...
@@ -101,8 +100,8 @@ Song::GetDuration() const
if
(
end_ms
>
0
)
return
(
end_ms
-
start_ms
)
/
1000.0
;
if
(
tag
==
nullptr
)
if
(
tag
.
time
<=
0
)
return
0
;
return
tag
->
time
-
start_ms
/
1000.0
;
return
tag
.
time
-
start_ms
/
1000.0
;
}
src/Song.hxx
View file @
d2cf7402
...
...
@@ -21,6 +21,7 @@
#define MPD_SONG_HXX
#include "util/list.h"
#include "tag/Tag.hxx"
#include "Compiler.h"
#include <string>
...
...
@@ -31,7 +32,6 @@
#define SONG_FILE "file: "
#define SONG_TIME "Time: "
struct
Tag
;
struct
Directory
;
class
DetachedSong
;
...
...
@@ -49,7 +49,7 @@ struct Song {
*/
struct
list_head
siblings
;
Tag
*
tag
;
Tag
tag
;
/**
* The #Directory that contains this song. May be nullptr if
...
...
src/SongFilter.cxx
View file @
d2cf7402
...
...
@@ -149,7 +149,7 @@ SongFilter::Item::Match(const Song &song) const
return
StringMatch
(
uri
.
c_str
());
}
return
song
.
tag
!=
NULL
&&
Match
(
*
song
.
tag
);
return
Match
(
song
.
tag
);
}
bool
...
...
src/SongPrint.cxx
View file @
d2cf7402
...
...
@@ -74,8 +74,7 @@ song_print_info(Client &client, const Song &song)
if
(
song
.
mtime
>
0
)
time_print
(
client
,
"Last-Modified"
,
song
.
mtime
);
if
(
song
.
tag
!=
nullptr
)
tag_print
(
client
,
*
song
.
tag
);
tag_print
(
client
,
song
.
tag
);
}
void
...
...
src/SongSave.cxx
View file @
d2cf7402
...
...
@@ -53,8 +53,7 @@ song_save(FILE *fp, const Song &song)
range_save
(
fp
,
song
.
start_ms
,
song
.
end_ms
);
if
(
song
.
tag
!=
nullptr
)
tag_save
(
fp
,
*
song
.
tag
);
tag_save
(
fp
,
song
.
tag
);
fprintf
(
fp
,
SONG_MTIME
": %li
\n
"
,
(
long
)
song
.
mtime
);
fprintf
(
fp
,
SONG_END
"
\n
"
);
...
...
src/SongSort.cxx
View file @
d2cf7402
...
...
@@ -30,14 +30,6 @@ extern "C" {
#include <stdlib.h>
static
const
char
*
tag_get_value_checked
(
const
Tag
*
tag
,
TagType
type
)
{
return
tag
!=
nullptr
?
tag
->
GetValue
(
type
)
:
nullptr
;
}
static
int
compare_utf8_string
(
const
char
*
a
,
const
char
*
b
)
{
...
...
@@ -55,11 +47,11 @@ compare_utf8_string(const char *a, const char *b)
* nullptr.
*/
static
int
compare_string_tag_item
(
const
Tag
*
a
,
const
Tag
*
b
,
compare_string_tag_item
(
const
Tag
&
a
,
const
Tag
&
b
,
TagType
type
)
{
return
compare_utf8_string
(
tag_get_value_checked
(
a
,
type
),
tag_get_value_checked
(
b
,
type
));
return
compare_utf8_string
(
a
.
GetValue
(
type
),
b
.
GetValue
(
type
));
}
/**
...
...
@@ -82,10 +74,10 @@ compare_number_string(const char *a, const char *b)
}
static
int
compare_tag_item
(
const
Tag
*
a
,
const
Tag
*
b
,
TagType
type
)
compare_tag_item
(
const
Tag
&
a
,
const
Tag
&
b
,
TagType
type
)
{
return
compare_number_string
(
tag_get_value_checked
(
a
,
type
),
tag_get_value_checked
(
b
,
type
));
return
compare_number_string
(
a
.
GetValue
(
type
),
b
.
GetValue
(
type
));
}
/* Only used for sorting/searchin a songvec, not general purpose compares */
...
...
src/SongUpdate.cxx
View file @
d2cf7402
...
...
@@ -98,8 +98,7 @@ Song::UpdateFile()
mtime
=
st
.
st_mtime
;
delete
tag
;
tag
=
tag_builder
.
CommitNew
();
tag_builder
.
Commit
(
tag
);
return
true
;
}
...
...
@@ -123,8 +122,7 @@ Song::UpdateFileInArchive()
if
(
!
tag_stream_scan
(
path_fs
.
c_str
(),
full_tag_handler
,
&
tag_builder
))
return
false
;
delete
tag
;
tag
=
tag_builder
.
CommitNew
();
tag_builder
.
Commit
(
tag
);
return
true
;
}
...
...
src/UpdateContainer.cxx
View file @
d2cf7402
...
...
@@ -113,10 +113,7 @@ update_container_file(Directory &directory,
plugin
.
ScanFile
(
child_path_fs
.
c_str
(),
add_tag_handler
,
&
tag_builder
);
if
(
tag_builder
.
IsDefined
())
song
->
tag
=
tag_builder
.
CommitNew
();
else
tag_builder
.
Clear
();
tag_builder
.
Commit
(
song
->
tag
);
db_lock
();
contdir
->
AddSong
(
song
);
...
...
src/db/ProxyDatabasePlugin.cxx
View file @
d2cf7402
...
...
@@ -524,7 +524,7 @@ Convert(const struct mpd_song *song)
for
(
const
auto
*
i
=
&
tag_table
[
0
];
i
->
d
!=
TAG_NUM_OF_ITEM_TYPES
;
++
i
)
Copy
(
tag
,
i
->
d
,
song
,
i
->
s
);
s
->
tag
=
tag
.
CommitNew
(
);
tag
.
Commit
(
s
->
tag
);
return
s
;
}
...
...
src/db/UpnpDatabasePlugin.cxx
View file @
d2cf7402
...
...
@@ -205,7 +205,7 @@ upnpItemToSong(UPnPDirObject &&dirent, const char *uri)
uri
=
dirent
.
url
.
c_str
();
Song
*
s
=
Song
::
NewFile
(
uri
,
nullptr
);
s
->
tag
=
new
Tag
(
std
::
move
(
dirent
.
tag
)
);
s
->
tag
=
std
::
move
(
dirent
.
tag
);
return
s
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment