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
027e562f
Commit
027e562f
authored
Aug 02, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
song/OptimizeFilter: optimization stage for filters
parent
2d212033
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
133 additions
and
0 deletions
+133
-0
Makefile.am
Makefile.am
+1
-0
DatabaseCommands.cxx
src/command/DatabaseCommands.cxx
+7
-0
QueueCommands.cxx
src/command/QueueCommands.cxx
+1
-0
AndSongFilter.hxx
src/song/AndSongFilter.hxx
+3
-0
Filter.cxx
src/song/Filter.cxx
+6
-0
Filter.hxx
src/song/Filter.hxx
+2
-0
NotSongFilter.hxx
src/song/NotSongFilter.hxx
+2
-0
OptimizeFilter.cxx
src/song/OptimizeFilter.cxx
+73
-0
OptimizeFilter.hxx
src/song/OptimizeFilter.hxx
+33
-0
TagSongFilter.hxx
src/song/TagSongFilter.hxx
+2
-0
UriSongFilter.hxx
src/song/UriSongFilter.hxx
+2
-0
ParseSongFilter.cxx
test/ParseSongFilter.cxx
+1
-0
No files found.
Makefile.am
View file @
027e562f
...
...
@@ -1039,6 +1039,7 @@ libsong_a_SOURCES = \
src/song/AudioFormatSongFilter.cxx src/song/AudioFormatSongFilter.hxx
\
src/song/AndSongFilter.cxx src/song/AndSongFilter.hxx
\
src/song/NotSongFilter.hxx
\
src/song/OptimizeFilter.cxx src/song/OptimizeFilter.hxx
\
src/song/Filter.cxx src/song/Filter.hxx
\
src/song/LightSong.cxx src/song/LightSong.hxx
...
...
src/command/DatabaseCommands.cxx
View file @
027e562f
...
...
@@ -105,6 +105,7 @@ handle_match(Client &client, Request args, Response &r, bool fold_case)
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
.
Optimize
();
const
DatabaseSelection
selection
(
""
,
true
,
&
filter
);
...
...
@@ -138,6 +139,7 @@ handle_match_add(Client &client, Request args, Response &r, bool fold_case)
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
.
Optimize
();
auto
&
partition
=
client
.
GetPartition
();
const
ScopeBulkEdit
bulk_edit
(
partition
);
...
...
@@ -172,6 +174,7 @@ handle_searchaddpl(Client &client, Request args, Response &r)
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
.
Optimize
();
const
Database
&
db
=
client
.
GetDatabaseOrThrow
();
...
...
@@ -206,6 +209,8 @@ handle_count(Client &client, Request args, Response &r)
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
.
Optimize
();
}
PrintSongCount
(
r
,
client
.
GetPartition
(),
""
,
&
filter
,
group
);
...
...
@@ -238,6 +243,7 @@ handle_list_file(Client &client, Request args, Response &r)
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
->
Optimize
();
}
PrintSongUris
(
r
,
client
.
GetPartition
(),
filter
.
get
());
...
...
@@ -300,6 +306,7 @@ handle_list(Client &client, Request args, Response &r)
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
->
Optimize
();
}
if
(
group_mask
.
Test
(
tagType
))
{
...
...
src/command/QueueCommands.cxx
View file @
027e562f
...
...
@@ -272,6 +272,7 @@ handle_playlist_match(Client &client, Request args, Response &r,
GetFullMessage
(
std
::
current_exception
()).
c_str
());
return
CommandResult
::
ERROR
;
}
filter
.
Optimize
();
playlist_print_find
(
r
,
client
.
GetPlaylist
(),
filter
);
return
CommandResult
::
OK
;
...
...
src/song/AndSongFilter.hxx
View file @
027e562f
...
...
@@ -31,6 +31,9 @@
class
AndSongFilter
final
:
public
ISongFilter
{
std
::
list
<
ISongFilterPtr
>
items
;
friend
void
OptimizeSongFilter
(
AndSongFilter
&
)
noexcept
;
friend
ISongFilterPtr
OptimizeSongFilter
(
ISongFilterPtr
)
noexcept
;
public
:
const
auto
&
GetItems
()
const
noexcept
{
return
items
;
...
...
src/song/Filter.cxx
View file @
027e562f
...
...
@@ -352,6 +352,12 @@ SongFilter::Parse(ConstBuffer<const char *> args, bool fold_case)
}
while
(
!
args
.
empty
());
}
void
SongFilter
::
Optimize
()
noexcept
{
OptimizeSongFilter
(
and_filter
);
}
bool
SongFilter
::
Match
(
const
LightSong
&
song
)
const
noexcept
{
...
...
src/song/Filter.hxx
View file @
027e562f
...
...
@@ -68,6 +68,8 @@ public:
*/
void
Parse
(
ConstBuffer
<
const
char
*>
args
,
bool
fold_case
=
false
);
void
Optimize
()
noexcept
;
gcc_pure
bool
Match
(
const
LightSong
&
song
)
const
noexcept
;
...
...
src/song/NotSongFilter.hxx
View file @
027e562f
...
...
@@ -28,6 +28,8 @@
class
NotSongFilter
final
:
public
ISongFilter
{
ISongFilterPtr
child
;
friend
ISongFilterPtr
OptimizeSongFilter
(
ISongFilterPtr
)
noexcept
;
public
:
template
<
typename
C
>
explicit
NotSongFilter
(
C
&&
_child
)
noexcept
...
...
src/song/OptimizeFilter.cxx
0 → 100644
View file @
027e562f
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "OptimizeFilter.hxx"
#include "AndSongFilter.hxx"
#include "NotSongFilter.hxx"
#include "TagSongFilter.hxx"
#include "UriSongFilter.hxx"
void
OptimizeSongFilter
(
AndSongFilter
&
af
)
noexcept
{
for
(
auto
i
=
af
.
items
.
begin
();
i
!=
af
.
items
.
end
();)
{
auto
f
=
OptimizeSongFilter
(
std
::
move
(
*
i
));
if
(
auto
*
nested
=
dynamic_cast
<
AndSongFilter
*>
(
f
.
get
()))
{
/* collapse nested #AndSongFilter instances */
af
.
items
.
splice
(
i
,
std
::
move
(
nested
->
items
));
i
=
af
.
items
.
erase
(
i
);
}
else
{
*
i
=
std
::
move
(
f
);
++
i
;
}
}
}
ISongFilterPtr
OptimizeSongFilter
(
ISongFilterPtr
f
)
noexcept
{
if
(
auto
*
af
=
dynamic_cast
<
AndSongFilter
*>
(
f
.
get
()))
{
/* first optimize all items */
OptimizeSongFilter
(
*
af
);
if
(
!
af
->
items
.
empty
()
&&
std
::
next
(
af
->
items
.
begin
())
==
af
->
items
.
end
())
/* only one item: the containing
#AndSongFilter can be removed */
return
std
::
move
(
af
->
items
.
front
());
}
else
if
(
auto
*
nf
=
dynamic_cast
<
NotSongFilter
*>
(
f
.
get
()))
{
auto
child
=
OptimizeSongFilter
(
std
::
move
(
nf
->
child
));
if
(
auto
*
tf
=
dynamic_cast
<
TagSongFilter
*>
(
child
.
get
()))
{
/* #TagSongFilter has its own "negated" flag,
so we can drop the #NotSongFilter
container */
tf
->
negated
=
!
tf
->
negated
;
return
child
;
}
else
if
(
auto
*
uf
=
dynamic_cast
<
UriSongFilter
*>
(
child
.
get
()))
{
/* same for #UriSongFilter */
uf
->
negated
=
!
uf
->
negated
;
return
child
;
}
nf
->
child
=
std
::
move
(
child
);
}
return
f
;
}
src/song/OptimizeFilter.hxx
0 → 100644
View file @
027e562f
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_SONG_OPTIMIZE_FILTER_HXX
#define MPD_SONG_OPTIMIZE_FILTER_HXX
#include "ISongFilter.hxx"
class
AndSongFilter
;
void
OptimizeSongFilter
(
AndSongFilter
&
af
)
noexcept
;
ISongFilterPtr
OptimizeSongFilter
(
ISongFilterPtr
f
)
noexcept
;
#endif
src/song/TagSongFilter.hxx
View file @
027e562f
...
...
@@ -38,6 +38,8 @@ class TagSongFilter final : public ISongFilter {
StringFilter
filter
;
friend
ISongFilterPtr
OptimizeSongFilter
(
ISongFilterPtr
)
noexcept
;
public
:
template
<
typename
V
>
TagSongFilter
(
TagType
_type
,
V
&&
_value
,
bool
fold_case
,
bool
_negated
)
...
...
src/song/UriSongFilter.hxx
View file @
027e562f
...
...
@@ -28,6 +28,8 @@ class UriSongFilter final : public ISongFilter {
bool
negated
;
friend
ISongFilterPtr
OptimizeSongFilter
(
ISongFilterPtr
)
noexcept
;
public
:
template
<
typename
V
>
UriSongFilter
(
V
&&
_value
,
bool
fold_case
,
bool
_negated
)
...
...
test/ParseSongFilter.cxx
View file @
027e562f
...
...
@@ -41,6 +41,7 @@ try {
SongFilter
filter
;
filter
.
Parse
(
ConstBuffer
<
const
char
*>
(
argv
+
1
,
argc
-
1
));
filter
.
Optimize
();
puts
(
filter
.
ToExpression
().
c_str
());
return
EXIT_SUCCESS
;
...
...
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