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
a885bdba
Commit
a885bdba
authored
Mar 13, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/Traits: pass string_view to Build()
parent
b6b15afb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
54 deletions
+29
-54
AllocatedPath.hxx
src/fs/AllocatedPath.hxx
+9
-17
Traits.cxx
src/fs/Traits.cxx
+16
-21
Traits.hxx
src/fs/Traits.hxx
+4
-16
No files found.
src/fs/AllocatedPath.hxx
View file @
a885bdba
...
@@ -56,10 +56,6 @@ class AllocatedPath {
...
@@ -56,10 +56,6 @@ class AllocatedPath {
AllocatedPath
(
string
&&
_value
)
noexcept
AllocatedPath
(
string
&&
_value
)
noexcept
:
value
(
std
::
move
(
_value
))
{}
:
value
(
std
::
move
(
_value
))
{}
static
AllocatedPath
Build
(
const_pointer
a
,
size_t
a_size
,
const_pointer
b
,
size_t
b_size
)
noexcept
{
return
AllocatedPath
(
Traits
::
Build
(
a
,
a_size
,
b
,
b_size
));
}
public
:
public
:
/**
/**
* Construct a "nulled" instance. Its IsNull() method will
* Construct a "nulled" instance. Its IsNull() method will
...
@@ -93,14 +89,13 @@ public:
...
@@ -93,14 +89,13 @@ public:
/**
/**
* Join two path components with the path separator.
* Join two path components with the path separator.
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
static
AllocatedPath
Build
(
const_pointer
a
,
const_pointer
b
)
noexcept
{
static
AllocatedPath
Build
(
string_view
a
,
string_view
b
)
noexcept
{
return
Build
(
a
,
Traits
::
GetLength
(
a
),
return
AllocatedPath
(
Traits
::
Build
(
a
,
b
));
b
,
Traits
::
GetLength
(
b
));
}
}
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
AllocatedPath
Build
(
Path
a
,
const_pointer
b
)
noexcept
{
static
AllocatedPath
Build
(
Path
a
,
string_view
b
)
noexcept
{
return
Build
(
a
.
c_str
(),
b
);
return
Build
(
a
.
c_str
(),
b
);
}
}
...
@@ -110,24 +105,21 @@ public:
...
@@ -110,24 +105,21 @@ public:
}
}
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
AllocatedPath
Build
(
const_pointer
a
,
static
AllocatedPath
Build
(
string_view
a
,
const
AllocatedPath
&
b
)
noexcept
{
const
AllocatedPath
&
b
)
noexcept
{
return
Build
(
a
,
Traits
::
GetLength
(
a
),
return
Build
(
a
,
b
.
value
);
b
.
value
.
c_str
(),
b
.
value
.
size
());
}
}
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
AllocatedPath
Build
(
const
AllocatedPath
&
a
,
static
AllocatedPath
Build
(
const
AllocatedPath
&
a
,
const_pointer
b
)
noexcept
{
string_view
b
)
noexcept
{
return
Build
(
a
.
value
.
c_str
(),
a
.
value
.
size
(),
return
Build
(
a
.
value
,
b
);
b
,
Traits
::
GetLength
(
b
));
}
}
gcc_pure
gcc_pure
static
AllocatedPath
Build
(
const
AllocatedPath
&
a
,
static
AllocatedPath
Build
(
const
AllocatedPath
&
a
,
const
AllocatedPath
&
b
)
noexcept
{
const
AllocatedPath
&
b
)
noexcept
{
return
Build
(
a
.
value
.
c_str
(),
a
.
value
.
size
(),
return
Build
(
a
.
value
,
b
.
value
);
b
.
value
.
c_str
(),
b
.
value
.
size
());
}
}
gcc_pure
gcc_pure
...
...
src/fs/Traits.cxx
View file @
a885bdba
...
@@ -24,29 +24,26 @@
...
@@ -24,29 +24,26 @@
template
<
typename
Traits
>
template
<
typename
Traits
>
typename
Traits
::
string
typename
Traits
::
string
BuildPathImpl
(
typename
Traits
::
const_pointer
a
,
size_t
a_size
,
BuildPathImpl
(
typename
Traits
::
string_view
a
,
typename
Traits
::
const_pointer
b
,
size_t
b_size
)
noexcept
typename
Traits
::
string_view
b
)
noexcept
{
{
assert
(
a
!=
nullptr
);
if
(
a
.
empty
())
assert
(
b
!=
nullptr
);
return
typename
Traits
::
string
(
b
);
if
(
b
.
empty
())
if
(
a_size
==
0
)
return
typename
Traits
::
string
(
a
);
return
typename
Traits
::
string
(
b
,
b_size
);
if
(
b_size
==
0
)
return
typename
Traits
::
string
(
a
,
a_size
);
typename
Traits
::
string
result
;
typename
Traits
::
string
result
;
result
.
reserve
(
a
_size
+
1
+
b_size
);
result
.
reserve
(
a
.
length
()
+
1
+
b
.
length
()
);
result
.
append
(
a
,
a_size
);
result
.
append
(
a
);
if
(
!
Traits
::
IsSeparator
(
a
[
a_size
-
1
]
))
if
(
!
Traits
::
IsSeparator
(
a
.
back
()
))
result
.
push_back
(
Traits
::
SEPARATOR
);
result
.
push_back
(
Traits
::
SEPARATOR
);
if
(
Traits
::
IsSeparator
(
b
[
0
]
))
if
(
Traits
::
IsSeparator
(
b
.
front
()
))
result
.
append
(
b
+
1
,
b_size
-
1
);
result
.
append
(
b
.
substr
(
1
)
);
else
else
result
.
append
(
b
,
b_size
);
result
.
append
(
b
);
return
result
;
return
result
;
}
}
...
@@ -122,10 +119,9 @@ RelativePathImpl(typename Traits::const_pointer base,
...
@@ -122,10 +119,9 @@ RelativePathImpl(typename Traits::const_pointer base,
}
}
PathTraitsFS
::
string
PathTraitsFS
::
string
PathTraitsFS
::
Build
(
const_pointer
a
,
size_t
a_size
,
PathTraitsFS
::
Build
(
string_view
a
,
string_view
b
)
noexcept
const_pointer
b
,
size_t
b_size
)
noexcept
{
{
return
BuildPathImpl
<
PathTraitsFS
>
(
a
,
a_size
,
b
,
b_size
);
return
BuildPathImpl
<
PathTraitsFS
>
(
a
,
b
);
}
}
PathTraitsFS
::
const_pointer
PathTraitsFS
::
const_pointer
...
@@ -161,10 +157,9 @@ PathTraitsFS::Apply(const_pointer base, const_pointer path) noexcept
...
@@ -161,10 +157,9 @@ PathTraitsFS::Apply(const_pointer base, const_pointer path) noexcept
}
}
PathTraitsUTF8
::
string
PathTraitsUTF8
::
string
PathTraitsUTF8
::
Build
(
const_pointer
a
,
size_t
a_size
,
PathTraitsUTF8
::
Build
(
string_view
a
,
string_view
b
)
noexcept
const_pointer
b
,
size_t
b_size
)
noexcept
{
{
return
BuildPathImpl
<
PathTraitsUTF8
>
(
a
,
a_size
,
b
,
b_size
);
return
BuildPathImpl
<
PathTraitsUTF8
>
(
a
,
b
);
}
}
PathTraitsUTF8
::
const_pointer
PathTraitsUTF8
::
const_pointer
...
...
src/fs/Traits.hxx
View file @
a885bdba
...
@@ -156,14 +156,8 @@ struct PathTraitsFS {
...
@@ -156,14 +156,8 @@ struct PathTraitsFS {
* remaining component is returned unchanged.
* remaining component is returned unchanged.
* If both components are empty strings, empty string is returned.
* If both components are empty strings, empty string is returned.
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
static
string
Build
(
const_pointer
a
,
size_t
a_size
,
static
string
Build
(
string_view
a
,
string_view
b
)
noexcept
;
const_pointer
b
,
size_t
b_size
)
noexcept
;
gcc_pure
gcc_nonnull_all
static
string
Build
(
const_pointer
a
,
const_pointer
b
)
noexcept
{
return
Build
(
a
,
GetLength
(
a
),
b
,
GetLength
(
b
));
}
/**
/**
* Interpret the given path as being relative to the given
* Interpret the given path as being relative to the given
...
@@ -271,14 +265,8 @@ struct PathTraitsUTF8 {
...
@@ -271,14 +265,8 @@ struct PathTraitsUTF8 {
* remaining component is returned unchanged.
* remaining component is returned unchanged.
* If both components are empty strings, empty string is returned.
* If both components are empty strings, empty string is returned.
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
static
string
Build
(
const_pointer
a
,
size_t
a_size
,
static
string
Build
(
string_view
a
,
string_view
b
)
noexcept
;
const_pointer
b
,
size_t
b_size
)
noexcept
;
gcc_pure
gcc_nonnull_all
static
string
Build
(
const_pointer
a
,
const_pointer
b
)
noexcept
{
return
Build
(
a
,
GetLength
(
a
),
b
,
GetLength
(
b
));
}
};
};
#endif
#endif
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