Replace static_string in parser

close #1574

This change yields a modest performance improment of 1-2% by replacing
the exception-based handling of buffer overflow with one based on
regular conditional checks.

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek authored and Vinnie Falco committed 2019-04-15 08:21:48 -07:00
1 parent b7a8fb5178
commit 2cfe3ba1b8
5 files changed
+100 -52

No files matched your search

@@ -491,7 +491,7 @@ parse_field(
char const* last,
string_view& name,
string_view& value,
static_string<max_obs_fold>& buf,
char_buffer<max_obs_fold>& buf,
error_code& ec)
{
/* header-field = field-name ":" OWS field-value OWS
@@ -607,63 +607,60 @@ parse_field(
if(token_last != first)
break;
}
buf.resize(0);
buf.append(first, token_last);
BOOST_ASSERT(! buf.empty());
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
buf.clear();
if (!buf.try_append(first, token_last))
{
for(;;)
ec = error::header_limit;
return;
}
BOOST_ASSERT(! buf.empty());
for(;;)
{
// eat leading ' ' and '\t'
for(;;++p)
{
// eat leading ' ' and '\t'
for(;;++p)
{
if(p + 1 > last)
{
ec = error::need_more;
return;
}
if(! (*p == ' ' || *p == '\t'))
break;
}
// parse to CRLF
first = p;
p = parse_token_to_eol(p, last, token_last, ec);
if(ec)
return;
if(! p)
{
ec = error::bad_value;
return;
}
// Look 1 char past the CRLF to handle obs-fold.
if(p + 1 > last)
{
ec = error::need_more;
return;
}
token_last = trim_back(token_last, first);
if(first != token_last)
if(! (*p == ' ' || *p == '\t'))
break;
}
// parse to CRLF
first = p;
p = parse_token_to_eol(p, last, token_last, ec);
if(ec)
return;
if(! p)
{
ec = error::bad_value;
return;
}
// Look 1 char past the CRLF to handle obs-fold.
if(p + 1 > last)
{
ec = error::need_more;
return;
}
token_last = trim_back(token_last, first);
if(first != token_last)
{
if (!buf.try_push_back(' ') ||
!buf.try_append(first, token_last))
{
buf.push_back(' ');
buf.append(first, token_last);
}
if(*p != ' ' && *p != '\t')
{
value = {buf.data(), buf.size()};
ec = error::header_limit;
return;
}
++p;
}
if(*p != ' ' && *p != '\t')
{
value = {buf.data(), buf.size()};
return;
}
++p;
}
#ifndef BOOST_NO_EXCEPTIONS
catch(std::length_error const&)
{
ec = error::header_limit;
return;
}
#endif
}