From 5def8f2a865e08057a1416f5766a87a9d63874f2 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 15 Jun 2018 15:28:25 -0700 Subject: [PATCH] Use string methods for copying bytes, not loops --- src/scanner.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/scanner.cc b/src/scanner.cc index 8421e50..c49858d 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -32,9 +32,8 @@ struct Scanner { if (tag.type == CUSTOM) { buffer[i++] = tag.custom_tag_name.size(); - for (char c : tag.custom_tag_name) { - buffer[i++] = c; - } + tag.custom_tag_name.copy(&buffer[i], tag.custom_tag_name.size()); + i += tag.custom_tag_name.size(); } } @@ -49,10 +48,9 @@ struct Scanner { Tag tag { static_cast(buffer[i]), "" }; i++; if (tag.type == CUSTOM) { - tag.custom_tag_name.resize(buffer[i++]); - for (unsigned j = 0; j < tag.custom_tag_name.size(); j++) { - tag.custom_tag_name[j] = buffer[i++]; - } + unsigned length = buffer[i++]; + tag.custom_tag_name.assign(&buffer[i], &buffer[i + length]); + i += length; } tags.push_back(tag); }