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
fe6094a8
Commit
fe6094a8
authored
Jan 07, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag/TagPool: use NewVarSize() to allocate TagPoolSlot
parent
8a30c799
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
21 deletions
+27
-21
TagPool.cxx
src/tag/TagPool.cxx
+27
-21
No files found.
src/tag/TagPool.cxx
View file @
fe6094a8
...
...
@@ -21,8 +21,7 @@
#include "TagPool.hxx"
#include "TagItem.hxx"
#include "util/Cast.hxx"
#include <glib.h>
#include "util/VarSize.hxx"
#include <assert.h>
#include <string.h>
...
...
@@ -35,8 +34,30 @@ struct TagPoolSlot {
TagPoolSlot
*
next
;
unsigned
char
ref
;
TagItem
item
;
TagPoolSlot
(
TagPoolSlot
*
_next
,
TagType
type
,
const
char
*
value
,
size_t
length
)
:
next
(
_next
),
ref
(
1
)
{
item
.
type
=
type
;
memcpy
(
item
.
value
,
value
,
length
);
item
.
value
[
length
]
=
0
;
}
static
TagPoolSlot
*
Create
(
TagPoolSlot
*
_next
,
TagType
type
,
const
char
*
value
,
size_t
length
);
}
gcc_packed
;
TagPoolSlot
*
TagPoolSlot
::
Create
(
TagPoolSlot
*
_next
,
TagType
type
,
const
char
*
value
,
size_t
length
)
{
TagPoolSlot
*
dummy
;
return
NewVarSize
<
TagPoolSlot
>
(
sizeof
(
dummy
->
item
.
value
),
length
+
1
,
_next
,
type
,
value
,
length
);
}
static
TagPoolSlot
*
slots
[
NUM_SLOTS
];
static
inline
unsigned
...
...
@@ -71,21 +92,6 @@ tag_item_to_slot(TagItem *item)
return
ContainerCast
(
item
,
TagPoolSlot
,
item
);
}
static
TagPoolSlot
*
slot_alloc
(
TagPoolSlot
*
next
,
TagType
type
,
const
char
*
value
,
int
length
)
{
TagPoolSlot
*
slot
;
slot
=
(
TagPoolSlot
*
)
g_malloc
(
sizeof
(
*
slot
)
-
sizeof
(
slot
->
item
.
value
)
+
length
+
1
);
slot
->
next
=
next
;
slot
->
ref
=
1
;
slot
->
item
.
type
=
type
;
memcpy
(
slot
->
item
.
value
,
value
,
length
);
slot
->
item
.
value
[
length
]
=
0
;
return
slot
;
}
TagItem
*
tag_pool_get_item
(
TagType
type
,
const
char
*
value
,
size_t
length
)
{
...
...
@@ -103,7 +109,7 @@ tag_pool_get_item(TagType type, const char *value, size_t length)
}
}
slot
=
slot_alloc
(
*
slot_p
,
type
,
value
,
length
);
slot
=
TagPoolSlot
::
Create
(
*
slot_p
,
type
,
value
,
length
);
*
slot_p
=
slot
;
return
&
slot
->
item
;
}
...
...
@@ -125,8 +131,8 @@ tag_pool_dup_item(TagItem *item)
TagPoolSlot
**
slot_p
=
&
slots
[
calc_hash_n
(
item
->
type
,
item
->
value
,
length
)
%
NUM_SLOTS
];
slot
=
slot_alloc
(
*
slot_p
,
item
->
type
,
item
->
value
,
strlen
(
item
->
value
));
slot
=
TagPoolSlot
::
Create
(
*
slot_p
,
item
->
type
,
item
->
value
,
strlen
(
item
->
value
));
*
slot_p
=
slot
;
return
&
slot
->
item
;
}
...
...
@@ -151,5 +157,5 @@ tag_pool_put_item(TagItem *item)
}
*
slot_p
=
slot
->
next
;
g_fre
e
(
slot
);
DeleteVarSiz
e
(
slot
);
}
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