Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Commented Feature: web::json::value::string overload with additional 'escaped_chars' parameter [261]

$
0
0
web::json::value::string method has only one parameter - actual string to wrap:

```
static _ASYNCRTIMP value __cdecl string(utility::string_t value);
```

Internally, it creates an instance of _String class using single-parameter constructor:

```
_String(utility::string_t value) : m_string(std::move(value))
{
m_has_escape_char = has_escape_chars(*this);
}
```

__has_escape_chars__ method uses find_first_of algorithm, which has linear complexity (times number of characters to look for):

```
bool web::json::details::_String::has_escape_chars(const _String &str)
{
static const auto escapes = U("\"\\\b\f\r\n\t");
return str.m_string.find_first_of(escapes) != utility::string_t::npos;
}

```

For large strings (we encode images as base64 and pass them to the client as JSON) such check has huge performance penalty.

I suggest to add overload of web::json::value::string that allows to specify whether check for escape characters or not:

```
static _ASYNCRTIMP value __cdecl string(utility::string_t value, bool escaped_chars);
```
Comments: Thanks Steve, I've just submitted pull request with new overload implementation :)

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>