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
7e8d254b
Commit
7e8d254b
authored
Dec 03, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tag: move code from Merge() to TagBuilder::Complement()
parent
6325c3f1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
40 deletions
+29
-40
Tag.cxx
src/tag/Tag.cxx
+4
-40
TagBuilder.cxx
src/tag/TagBuilder.cxx
+19
-0
TagBuilder.hxx
src/tag/TagBuilder.hxx
+6
-0
No files found.
src/tag/Tag.cxx
View file @
7e8d254b
...
...
@@ -22,6 +22,7 @@
#include "TagPool.hxx"
#include "TagString.hxx"
#include "TagSettings.h"
#include "TagBuilder.hxx"
#include "util/ASCII.hxx"
#include <glib.h>
...
...
@@ -108,46 +109,9 @@ Tag::Tag(const Tag &other)
Tag
*
Tag
::
Merge
(
const
Tag
&
base
,
const
Tag
&
add
)
{
unsigned
n
;
/* allocate new tag object */
Tag
*
ret
=
new
Tag
();
ret
->
time
=
add
.
time
>
0
?
add
.
time
:
base
.
time
;
ret
->
num_items
=
base
.
num_items
+
add
.
num_items
;
ret
->
items
=
ret
->
num_items
>
0
?
(
TagItem
**
)
g_malloc
(
items_size
(
*
ret
))
:
nullptr
;
tag_pool_lock
.
lock
();
/* copy all items from "add" */
for
(
unsigned
i
=
0
;
i
<
add
.
num_items
;
++
i
)
ret
->
items
[
i
]
=
tag_pool_dup_item
(
add
.
items
[
i
]);
n
=
add
.
num_items
;
/* copy additional items from "base" */
for
(
unsigned
i
=
0
;
i
<
base
.
num_items
;
++
i
)
if
(
!
add
.
HasType
(
base
.
items
[
i
]
->
type
))
ret
->
items
[
n
++
]
=
tag_pool_dup_item
(
base
.
items
[
i
]);
tag_pool_lock
.
unlock
();
assert
(
n
<=
ret
->
num_items
);
if
(
n
<
ret
->
num_items
)
{
/* some tags were not copied - shrink ret->items */
assert
(
n
>
0
);
ret
->
num_items
=
n
;
ret
->
items
=
(
TagItem
**
)
g_realloc
(
ret
->
items
,
items_size
(
*
ret
));
}
return
ret
;
TagBuilder
builder
(
base
);
builder
.
Complement
(
add
);
return
builder
.
Commit
();
}
Tag
*
...
...
src/tag/TagBuilder.cxx
View file @
7e8d254b
...
...
@@ -109,6 +109,25 @@ TagBuilder::HasType(TagType type) const
return
false
;
}
void
TagBuilder
::
Complement
(
const
Tag
&
other
)
{
if
(
time
<=
0
)
time
=
other
.
time
;
has_playlist
|=
other
.
has_playlist
;
items
.
reserve
(
items
.
size
()
+
other
.
num_items
);
tag_pool_lock
.
lock
();
for
(
unsigned
i
=
0
,
n
=
other
.
num_items
;
i
!=
n
;
++
i
)
{
TagItem
*
item
=
other
.
items
[
i
];
if
(
!
HasType
(
item
->
type
))
items
.
push_back
(
tag_pool_dup_item
(
item
));
}
tag_pool_lock
.
unlock
();
}
inline
void
TagBuilder
::
AddItemInternal
(
TagType
type
,
const
char
*
value
,
size_t
length
)
{
...
...
src/tag/TagBuilder.hxx
View file @
7e8d254b
...
...
@@ -119,6 +119,12 @@ public:
bool
HasType
(
TagType
type
)
const
;
/**
* Copy attributes and items from the other object that do not
* exist in this object.
*/
void
Complement
(
const
Tag
&
other
);
/**
* Appends a new tag item.
*
* @param type the type of the new tag item
...
...
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