mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-27 02:23:26 +03:00
Allocate some data in advance in string algorithm
This commit is contained in:
parent
12a732d1fa
commit
82833608c9
@ -59,6 +59,7 @@ Vector<StringView> split(StringView str, char separator)
|
|||||||
String escape(StringView str, StringView characters, char escape)
|
String escape(StringView str, StringView characters, char escape)
|
||||||
{
|
{
|
||||||
String res;
|
String res;
|
||||||
|
res.reserve(str.length());
|
||||||
for (auto& c : str)
|
for (auto& c : str)
|
||||||
{
|
{
|
||||||
if (contains(characters, c))
|
if (contains(characters, c))
|
||||||
@ -71,6 +72,7 @@ String escape(StringView str, StringView characters, char escape)
|
|||||||
String unescape(StringView str, StringView characters, char escape)
|
String unescape(StringView str, StringView characters, char escape)
|
||||||
{
|
{
|
||||||
String res;
|
String res;
|
||||||
|
res.reserve(str.length());
|
||||||
for (auto& c : str)
|
for (auto& c : str)
|
||||||
{
|
{
|
||||||
if (contains(characters, c) and not res.empty() and res.back() == escape)
|
if (contains(characters, c) and not res.empty() and res.back() == escape)
|
||||||
@ -84,6 +86,7 @@ String unescape(StringView str, StringView characters, char escape)
|
|||||||
String indent(StringView str, StringView indent)
|
String indent(StringView str, StringView indent)
|
||||||
{
|
{
|
||||||
String res;
|
String res;
|
||||||
|
res.reserve(str.length());
|
||||||
bool was_eol = true;
|
bool was_eol = true;
|
||||||
for (ByteCount i = 0; i < str.length(); ++i)
|
for (ByteCount i = 0; i < str.length(); ++i)
|
||||||
{
|
{
|
||||||
@ -144,6 +147,7 @@ bool subsequence_match(StringView str, StringView subseq)
|
|||||||
String expand_tabs(StringView line, CharCount tabstop, CharCount col)
|
String expand_tabs(StringView line, CharCount tabstop, CharCount col)
|
||||||
{
|
{
|
||||||
String res;
|
String res;
|
||||||
|
res.reserve(line.length());
|
||||||
using Utf8It = utf8::iterator<const char*>;
|
using Utf8It = utf8::iterator<const char*>;
|
||||||
for (Utf8It it = line.begin(); it.base() < line.end(); ++it)
|
for (Utf8It it = line.begin(); it.base() < line.end(); ++it)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user