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
91efe1cb
Commit
91efe1cb
authored
Jan 09, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Directory: convert to fixed-size struct
Using a variable-size struct with embedded string is not worth the trouble here. There are not so many Directory objects.
parent
735241f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
56 deletions
+15
-56
Directory.cxx
src/Directory.cxx
+6
-37
Directory.hxx
src/Directory.hxx
+9
-19
No files found.
src/Directory.cxx
View file @
91efe1cb
...
...
@@ -25,7 +25,7 @@
#include "SongSort.hxx"
#include "Song.hxx"
#include "fs/Traits.hxx"
#include "util/
VarSize
.hxx"
#include "util/
Alloc
.hxx"
#include "util/Error.hxx"
extern
"C"
{
...
...
@@ -38,23 +38,11 @@ extern "C" {
#include <string.h>
#include <stdlib.h>
inline
Directory
*
Directory
::
Allocate
(
const
char
*
path
)
{
assert
(
path
!=
nullptr
);
return
NewVarSize
<
Directory
>
(
sizeof
(
Directory
::
path
),
strlen
(
path
)
+
1
,
path
);
}
Directory
::
Directory
(
const
char
*
_path
)
:
mtime
(
0
),
have_stat
(
false
)
Directory
::
Directory
(
const
char
*
_path_utf8
,
Directory
*
_parent
)
:
parent
(
_parent
),
path
(
_path_utf8
)
{
INIT_LIST_HEAD
(
&
children
);
INIT_LIST_HEAD
(
&
songs
);
strcpy
(
path
,
_path
);
}
Directory
::~
Directory
()
...
...
@@ -68,25 +56,6 @@ Directory::~Directory()
child
->
Free
();
}
Directory
*
Directory
::
NewGeneric
(
const
char
*
path
,
Directory
*
parent
)
{
assert
(
path
!=
nullptr
);
assert
((
*
path
==
0
)
==
(
parent
==
nullptr
));
Directory
*
directory
=
Allocate
(
path
);
directory
->
parent
=
parent
;
return
directory
;
}
void
Directory
::
Free
()
{
DeleteVarSize
(
this
);
}
void
Directory
::
Delete
()
{
...
...
@@ -102,7 +71,7 @@ Directory::GetName() const
{
assert
(
!
IsRoot
());
return
PathTraitsUTF8
::
GetBase
(
path
);
return
PathTraitsUTF8
::
GetBase
(
path
.
c_str
()
);
}
Directory
*
...
...
@@ -123,7 +92,7 @@ Directory::CreateChild(const char *name_utf8)
path_utf8
=
allocated
;
}
Directory
*
child
=
NewGeneric
(
path_utf8
,
this
);
Directory
*
child
=
new
Directory
(
path_utf8
,
this
);
g_free
(
allocated
);
list_add_tail
(
&
child
->
siblings
,
&
children
);
...
...
@@ -264,7 +233,7 @@ directory_cmp(gcc_unused void *priv,
{
const
Directory
*
a
=
(
const
Directory
*
)
_a
;
const
Directory
*
b
=
(
const
Directory
*
)
_b
;
return
g_utf8_collate
(
a
->
path
,
b
->
path
);
return
g_utf8_collate
(
a
->
path
.
c_str
(),
b
->
path
.
c_str
()
);
}
void
...
...
src/Directory.hxx
View file @
91efe1cb
...
...
@@ -26,6 +26,8 @@
#include "DatabaseVisitor.hxx"
#include "PlaylistVector.hxx"
#include <string>
#include <sys/types.h>
#define DEVICE_INARCHIVE (dev_t)(-1)
...
...
@@ -49,10 +51,6 @@ class SongFilter;
class
Error
;
struct
Directory
{
template
<
class
T
,
typename
...
Args
>
friend
T
*
NewVarSize
(
size_t
declared_tail_size
,
size_t
real_tail_size
,
Args
&&
...
args
);
/**
* Pointers to the siblings of this directory within the
* parent directory. It is unused (undefined) in the root
...
...
@@ -86,36 +84,28 @@ struct Directory {
ino_t
inode
;
dev_t
device
;
bool
have_stat
;
/* not needed if ino_t == dev_t == 0 is impossible */
char
path
[
sizeof
(
long
)];
protected
:
Directory
(
const
char
*
path
);
gcc_malloc
gcc_nonnull_all
static
Directory
*
Allocate
(
const
char
*
path
);
std
::
string
path
;
public
:
Directory
(
const
char
*
_path_utf8
,
Directory
*
_parent
);
~
Directory
();
/**
* Generic constructor for #Directory object.
*/
gcc_malloc
static
Directory
*
NewGeneric
(
const
char
*
path_utf8
,
Directory
*
parent
);
/**
* Create a new root #Directory object.
*/
gcc_malloc
static
Directory
*
NewRoot
()
{
return
NewGeneric
(
""
,
nullptr
);
return
new
Directory
(
""
,
nullptr
);
}
/**
* Free this #Directory object (and the whole object tree within it),
* assuming it was already removed from the parent.
*/
void
Free
();
void
Free
()
{
delete
this
;
}
/**
* Remove this #Directory object from its parent and free it. This
...
...
@@ -178,7 +168,7 @@ public:
gcc_pure
const
char
*
GetPath
()
const
{
return
path
;
return
path
.
c_str
()
;
}
/**
...
...
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