From 89845fda946fe6f471e3b7e6a77f69f526e38a74 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Wed, 10 Oct 2018 13:55:21 +0300 Subject: Reserve vector storage in the convert filter code --- src/mbgl/style/conversion/filter.cpp | 9 ++++++--- src/mbgl/style/conversion/function.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mbgl/style/conversion/filter.cpp b/src/mbgl/style/conversion/filter.cpp index fc25ab0b0d..18a29ed808 100644 --- a/src/mbgl/style/conversion/filter.cpp +++ b/src/mbgl/style/conversion/filter.cpp @@ -118,7 +118,8 @@ ParseResult convertLiteral(const Convertible& convertible, Error& error) { optional>> convertLiteralArray(const Convertible &input, Error& error, std::size_t startIndex = 0) { std::vector> output; - for (std::size_t i = startIndex; i < arrayLength(input); i++) { + output.reserve(arrayLength(input)); + for (std::size_t i = startIndex; i < arrayLength(input); ++i) { ParseResult literal = convertLiteral(arrayMember(input, i), error); if (!literal) { return nullopt; @@ -178,7 +179,8 @@ ParseResult convertLegacyInFilter(const Convertible& values, Error& error) { optional>> convertLegacyFilterArray(const Convertible &input, Error& error, std::size_t startIndex = 0) { std::vector> output; - for (std::size_t i = startIndex; i < arrayLength(input); i++) { + output.reserve(arrayLength(input)); + for (std::size_t i = startIndex; i < arrayLength(input); ++i) { optional> child = convertLegacyFilter(arrayMember(input, i), error); if (!child) { return nullopt; @@ -225,7 +227,8 @@ optional serializeLegacyFilter(const Convertible& values) { return nullopt; } else if (isArray(values)) { std::vector result; - for (std::size_t i = 0; i < arrayLength(values); i++) { + result.reserve(arrayLength(values)); + for (std::size_t i = 0; i < arrayLength(values); ++i) { auto arrayValue = serializeLegacyFilter(arrayMember(values, i)); if (arrayValue) { result.push_back(*arrayValue); diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 6ee962fb77..69fb0725d8 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -78,7 +78,7 @@ optional> convertFunctionToExpression(const Convertible& v return nullopt; } - optional defaultValue; + optional defaultValue{}; auto defaultValueValue = objectMember(value, "default"); if (defaultValueValue) { -- cgit v1.2.1