From f134c847ac88dfd6f528f596dcb9370a45ce7d43 Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Sun, 5 Nov 2023 13:11:02 -0500 Subject: [PATCH] refactor(i18n): prefer Vector over std::vector Reduce our use of std::vector to reduce binary bloat: https://github.com/quick-lint/quick-lint-js/issues/689 --- src/quick-lint-js/i18n/locale.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/quick-lint-js/i18n/locale.cpp b/src/quick-lint-js/i18n/locale.cpp index d02ca9fe73..78f0604db8 100644 --- a/src/quick-lint-js/i18n/locale.cpp +++ b/src/quick-lint-js/i18n/locale.cpp @@ -1,6 +1,8 @@ // Copyright (C) 2020 Matthew "strager" Glazar // See end of file for extended copyright information. +#include "quick-lint-js/container/linked-bump-allocator.h" +#include "quick-lint-js/container/vector.h" #include #include #include @@ -108,12 +110,13 @@ QLJS_WARNING_IGNORE_GCC("-Wzero-as-null-pointer-constant") template void locale_name_combinations(std::string_view locale_name, Func&& callback) { + Linked_Bump_Allocator temporary_allocator("locale_name_combinations"); Locale_Parts parts = parse_locale(locale_name); - std::vector locale; - std::size_t max_locale_size = locale_name.size(); + Vector locale("locale", &temporary_allocator); + Vector_Size max_locale_size = narrow_cast(locale_name.size()); locale.reserve(max_locale_size); - locale.insert(locale.end(), parts.language().begin(), parts.language().end()); + locale += parts.language(); unsigned present_parts_mask = 0; for (std::size_t part_index = 1; part_index < 4; ++part_index) { @@ -148,7 +151,7 @@ void locale_name_combinations(std::string_view locale_name, Func&& callback) { if (mask & (1 << part_index)) { std::string_view part = parts.parts[part_index]; locale.push_back(locale_part_separators[part_index - 1]); - locale.insert(locale.end(), part.begin(), part.end()); + locale += part; } } QLJS_ASSERT(locale.size() <= max_locale_size);