Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
506de554
Commit
506de554
authored
Jan 17, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Less strlen
parent
04557898
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
src/template.h
src/template.h
+20
-7
No files found.
src/template.h
View file @
506de554
...
@@ -187,6 +187,10 @@ inline std::unique_ptr<char[]> strcopy(const char *val) {
...
@@ -187,6 +187,10 @@ inline std::unique_ptr<char[]> strcopy(const char *val) {
return
strcopy
(
val
,
val
+
strlen
(
val
));
return
strcopy
(
val
,
val
+
strlen
(
val
));
}
}
inline
std
::
unique_ptr
<
char
[]
>
strcopy
(
const
char
*
val
,
size_t
n
)
{
return
strcopy
(
val
,
val
+
n
);
}
// Returns a copy of val.c_str().
// Returns a copy of val.c_str().
inline
std
::
unique_ptr
<
char
[]
>
strcopy
(
const
std
::
string
&
val
)
{
inline
std
::
unique_ptr
<
char
[]
>
strcopy
(
const
std
::
string
&
val
)
{
return
strcopy
(
std
::
begin
(
val
),
std
::
end
(
val
));
return
strcopy
(
std
::
begin
(
val
),
std
::
end
(
val
));
...
@@ -199,26 +203,35 @@ inline std::unique_ptr<char[]> strcopy(const std::unique_ptr<char[]> &val) {
...
@@ -199,26 +203,35 @@ inline std::unique_ptr<char[]> strcopy(const std::unique_ptr<char[]> &val) {
return
strcopy
(
val
.
get
());
return
strcopy
(
val
.
get
());
}
}
inline
std
::
unique_ptr
<
char
[]
>
strcopy
(
const
std
::
unique_ptr
<
char
[]
>
&
val
,
size_t
n
)
{
if
(
!
val
)
{
return
nullptr
;
}
return
strcopy
(
val
.
get
(),
val
.
get
()
+
n
);
}
// VString represents string. It has c_str() and size() functions to
// VString represents string. It has c_str() and size() functions to
// mimic std::string. It manages buffer by itself. Just like
// mimic std::string. It manages buffer by itself. Just like
// std::string, c_str() returns NULL-terminated string, but NULL
// std::string, c_str() returns NULL-terminated string, but NULL
// character may appear before the final terminal NULL.
// character may appear before the final terminal NULL.
struct
VString
{
struct
VString
{
VString
()
:
len
(
0
)
{}
VString
()
:
len
(
0
)
{}
VString
(
const
char
*
s
,
size_t
slen
)
:
base
(
strcopy
(
s
)),
len
(
slen
)
{}
VString
(
const
char
*
s
,
size_t
slen
)
:
len
(
slen
),
base
(
strcopy
(
s
,
len
)
)
{}
VString
(
const
char
*
s
)
:
base
(
strcopy
(
s
)),
len
(
strlen
(
s
))
{}
VString
(
const
char
*
s
)
:
len
(
strlen
(
s
)),
base
(
strcopy
(
s
,
len
))
{}
VString
(
const
std
::
string
&
s
)
:
base
(
strcopy
(
s
)),
len
(
s
.
size
(
))
{}
VString
(
const
std
::
string
&
s
)
:
len
(
s
.
size
()),
base
(
strcopy
(
s
))
{}
template
<
typename
InputIt
>
template
<
typename
InputIt
>
VString
(
InputIt
first
,
InputIt
last
)
VString
(
InputIt
first
,
InputIt
last
)
:
base
(
strcopy
(
first
,
last
)),
len
(
std
::
distance
(
first
,
last
))
{}
:
len
(
std
::
distance
(
first
,
last
)),
base
(
strcopy
(
first
,
last
))
{}
VString
(
const
VString
&
other
)
:
base
(
strcopy
(
other
.
base
)),
len
(
other
.
len
)
{}
VString
(
const
VString
&
other
)
:
len
(
other
.
len
),
base
(
strcopy
(
other
.
base
,
other
.
len
))
{}
VString
(
VString
&&
)
=
default
;
VString
(
VString
&&
)
=
default
;
VString
&
operator
=
(
const
VString
&
other
)
{
VString
&
operator
=
(
const
VString
&
other
)
{
if
(
this
==
&
other
)
{
if
(
this
==
&
other
)
{
return
*
this
;
return
*
this
;
}
}
base
=
strcopy
(
other
.
base
);
len
=
other
.
len
;
len
=
other
.
len
;
base
=
strcopy
(
other
.
base
,
other
.
len
);
return
*
this
;
return
*
this
;
}
}
VString
&
operator
=
(
VString
&&
other
)
=
default
;
VString
&
operator
=
(
VString
&&
other
)
=
default
;
...
@@ -226,8 +239,8 @@ struct VString {
...
@@ -226,8 +239,8 @@ struct VString {
const
char
*
c_str
()
const
{
return
base
.
get
();
}
const
char
*
c_str
()
const
{
return
base
.
get
();
}
size_t
size
()
const
{
return
len
;
}
size_t
size
()
const
{
return
len
;
}
std
::
unique_ptr
<
char
[]
>
base
;
size_t
len
;
size_t
len
;
std
::
unique_ptr
<
char
[]
>
base
;
};
};
// StringAdaptor behaves like simple string, but it does not own
// StringAdaptor behaves like simple string, but it does not own
...
...
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