From 6036c620f507bc365d2032636705334f28d85e0e Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Sat, 4 Nov 2023 19:53:39 -0400 Subject: [PATCH] refactor(container): remove allocator template param from Bump_Vector Bump_Vector is only instantiated with Linked_Bump_Allocator for Bump_Allocator. Inline Bump_Allocator, making some code less verbose. --- src/quick-lint-js/c-api-diag-reporter.h | 9 +++--- src/quick-lint-js/cli/options.cpp | 9 +++--- .../container/vector-profiler.cpp | 6 ++-- src/quick-lint-js/container/vector.h | 20 ++++++------ src/quick-lint-js/debug/find-debug-server.cpp | 3 +- src/quick-lint-js/diag/diag-code-list.cpp | 29 +++++++---------- src/quick-lint-js/diag/diag-code-list.h | 8 ++--- src/quick-lint-js/fe/expression.h | 6 ++-- src/quick-lint-js/fe/lex.cpp | 4 +-- src/quick-lint-js/fe/parse-class.cpp | 13 ++++---- src/quick-lint-js/fe/parse-expression.cpp | 4 +-- src/quick-lint-js/fe/parse-statement.cpp | 8 ++--- src/quick-lint-js/fe/parse.cpp | 4 +-- src/quick-lint-js/fe/parse.h | 2 +- src/quick-lint-js/fe/token.h | 2 +- src/quick-lint-js/i18n/po-parser.cpp | 6 ++-- .../i18n/translation-table-compiler.cpp | 6 ++-- src/quick-lint-js/i18n/translation.cpp | 6 ++-- src/quick-lint-js/io/event-loop-poll.cpp | 6 ++-- .../lsp/lsp-workspace-configuration.h | 2 +- src/quick-lint-js/port/child-process.cpp | 5 ++- src/quick-lint-js/reflection/cxx-parser.cpp | 4 +-- src/quick-lint-js/reflection/cxx-parser.h | 8 ++--- test/quick-lint-js/tjson.cpp | 4 +-- test/test-vector.cpp | 32 +++++++++---------- tools/compile-translations.cpp | 6 ++-- tools/generate-trace-sources.cpp | 13 +++----- 27 files changed, 104 insertions(+), 121 deletions(-) diff --git a/src/quick-lint-js/c-api-diag-reporter.h b/src/quick-lint-js/c-api-diag-reporter.h index 3e1cfe6f5f..4338b64b99 100644 --- a/src/quick-lint-js/c-api-diag-reporter.h +++ b/src/quick-lint-js/c-api-diag-reporter.h @@ -42,8 +42,8 @@ class C_API_Diag_Reporter final : public Diag_Reporter { Translator translator_; Monotonic_Allocator allocator_{"C_API_Diag_Reporter::allocator_"}; - Bump_Vector diagnostics_{ - "C_API_Diag_Reporter::diagnostics_", &this->allocator_}; + Bump_Vector diagnostics_{"C_API_Diag_Reporter::diagnostics_", + &this->allocator_}; const Char8 *input_; std::optional locator_; Monotonic_Allocator string_allocator_{ @@ -68,9 +68,8 @@ class C_API_Diag_Formatter private: C_API_Diag_Reporter *reporter_; - Bump_Vector current_message_{ - "C_API_Diag_Reporter::current_message_", - &this->reporter_->string_allocator_}; + Bump_Vector current_message_{"C_API_Diag_Reporter::current_message_", + &this->reporter_->string_allocator_}; }; QLJS_WARNING_PUSH diff --git a/src/quick-lint-js/cli/options.cpp b/src/quick-lint-js/cli/options.cpp index 605f0dbc04..943cdeffbc 100644 --- a/src/quick-lint-js/cli/options.cpp +++ b/src/quick-lint-js/cli/options.cpp @@ -35,13 +35,12 @@ Options parse_options(int argc, char** argv, Monotonic_Allocator* allocator) { const char* arg_var; } next_vim_file_bufnr; - Bump_Vector files_to_lint("files_to_lint", - allocator); - Bump_Vector error_unrecognized_options( + Bump_Vector files_to_lint("files_to_lint", allocator); + Bump_Vector error_unrecognized_options( "error_unrecognized_options", allocator); - Bump_Vector warning_vim_bufnr_without_file( + Bump_Vector warning_vim_bufnr_without_file( "warning_vim_bufnr_without_file", allocator); - Bump_Vector warning_language_without_file( + Bump_Vector warning_language_without_file( "warning_language_without_file", allocator); const char* next_path_for_config_search = nullptr; diff --git a/src/quick-lint-js/container/vector-profiler.cpp b/src/quick-lint-js/container/vector-profiler.cpp index 72bfff3c4f..1a75c1a9a7 100644 --- a/src/quick-lint-js/container/vector-profiler.cpp +++ b/src/quick-lint-js/container/vector-profiler.cpp @@ -146,14 +146,12 @@ Vector_Max_Size_Histogram_By_Owner::histogram( // NOTE(strager): We use Raw_Bump_Vector to prevent vector profiling code from // emitting events itself. - Raw_Bump_Vector + Raw_Bump_Vector out_entries_by_owner(memory); out_entries_by_owner.reserve( narrow_cast(stable_histogram.size())); for (auto &[owner, counts] : stable_histogram) { - Raw_Bump_Vector - out_entries(memory); + Raw_Bump_Vector out_entries(memory); out_entries.reserve(narrow_cast(counts.size())); for (auto &[size, count] : counts) { out_entries.push_back(Trace_Vector_Max_Size_Histogram_Entry{ diff --git a/src/quick-lint-js/container/vector.h b/src/quick-lint-js/container/vector.h index dfa0a301f1..34506ddf1c 100644 --- a/src/quick-lint-js/container/vector.h +++ b/src/quick-lint-js/container/vector.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -91,11 +92,11 @@ class Uninstrumented_Vector : private Vector { using Bump_Vector_Size = std::ptrdiff_t; -template +template class Raw_Bump_Vector { public: using value_type = T; - using allocator_type = Bump_Allocator *; + using allocator_type = Linked_Bump_Allocator *; using size_type = Bump_Vector_Size; using difference_type = Bump_Vector_Size; using reference = T &; @@ -107,7 +108,8 @@ class Raw_Bump_Vector { static_assert(is_winkable_v); - explicit Raw_Bump_Vector(Bump_Allocator *allocator) : allocator_(allocator) {} + explicit Raw_Bump_Vector(Linked_Bump_Allocator *allocator) + : allocator_(allocator) {} Raw_Bump_Vector(const Raw_Bump_Vector &) = delete; Raw_Bump_Vector &operator=(const Raw_Bump_Vector &) = delete; @@ -124,7 +126,7 @@ class Raw_Bump_Vector { ~Raw_Bump_Vector() { this->clear(); } - Bump_Allocator *get_allocator() const { return this->allocator_; } + Linked_Bump_Allocator *get_allocator() const { return this->allocator_; } bool empty() const { return this->data_ == this->data_end_; } size_type size() const { @@ -338,15 +340,15 @@ class Raw_Bump_Vector { T *data_end_ = nullptr; T *capacity_end_ = nullptr; - Bump_Allocator *allocator_; + Linked_Bump_Allocator *allocator_; }; #if QLJS_FEATURE_VECTOR_PROFILING -template -using Bump_Vector = Instrumented_Vector>; +template +using Bump_Vector = Instrumented_Vector>; #else -template -using Bump_Vector = Uninstrumented_Vector>; +template +using Bump_Vector = Uninstrumented_Vector>; #endif } diff --git a/src/quick-lint-js/debug/find-debug-server.cpp b/src/quick-lint-js/debug/find-debug-server.cpp index 3384906c36..398dd3a47e 100644 --- a/src/quick-lint-js/debug/find-debug-server.cpp +++ b/src/quick-lint-js/debug/find-debug-server.cpp @@ -258,8 +258,7 @@ void enumerate_all_process_thread_names(Callback&& callback) { #if defined(__linux__) Span find_debug_servers(Monotonic_Allocator* allocator) { - Bump_Vector debug_servers( - "debug_servers", allocator); + Bump_Vector debug_servers("debug_servers", allocator); enumerate_all_process_thread_names([&](std::string_view process_id_string, std::string_view thread_name) { diff --git a/src/quick-lint-js/diag/diag-code-list.cpp b/src/quick-lint-js/diag/diag-code-list.cpp index a0bc6b58af..7f44f3499d 100644 --- a/src/quick-lint-js/diag/diag-code-list.cpp +++ b/src/quick-lint-js/diag/diag-code-list.cpp @@ -30,16 +30,13 @@ Parsed_Diag_Code_List parse_diag_code_list(const char* const raw_diag_code_list, return '0' <= c && c <= '9'; }; - Bump_Vector included_codes( - "included_codes", allocator); - Bump_Vector excluded_codes( - "excluded_codes", allocator); - Bump_Vector included_categories( - "included_categories", allocator); - Bump_Vector excluded_categories( - "excluded_categories", allocator); - Bump_Vector unexpected("unexpected", - allocator); + Bump_Vector included_codes("included_codes", allocator); + Bump_Vector excluded_codes("excluded_codes", allocator); + Bump_Vector included_categories("included_categories", + allocator); + Bump_Vector excluded_categories("excluded_categories", + allocator); + Bump_Vector unexpected("unexpected", allocator); bool override_defaults = false; std::size_t i = 0; @@ -143,11 +140,10 @@ void Compiled_Diag_Code_List::add(const Parsed_Diag_Code_List& diag_code_list) { Span Compiled_Diag_Code_List::parse_errors( std::string_view cli_option_name, Monotonic_Allocator* allocator) const { - Bump_Vector errors("errors", - allocator); + Bump_Vector errors("errors", allocator); if (this->has_missing_predicate_error_) { // TODO(#1102): Make this code pretty. - Bump_Vector error("error", allocator); + Bump_Vector error("error", allocator); error += cli_option_name; error += " must be given at least one category or code"sv; errors.emplace_back(error.release_to_string_view()); @@ -157,12 +153,11 @@ Span Compiled_Diag_Code_List::parse_errors( Span Compiled_Diag_Code_List::parse_warnings( Monotonic_Allocator* allocator) const { - Bump_Vector warnings("warnings", - allocator); + Bump_Vector warnings("warnings", allocator); auto check_category = [&](std::string_view category) { if (category != "all") { // TODO(#1102): Make this code pretty. - Bump_Vector warning("warning", allocator); + Bump_Vector warning("warning", allocator); warning += "unknown error category: "sv; warning += category; warnings.emplace_back(warning.release_to_string_view()); @@ -180,7 +175,7 @@ Span Compiled_Diag_Code_List::parse_warnings( for (std::string_view code : this->unknown_codes_) { // TODO(#1102): Make this code pretty. - Bump_Vector warning("warning", allocator); + Bump_Vector warning("warning", allocator); warning += "unknown error code: "sv; warning += code; warnings.emplace_back(warning.release_to_string_view()); diff --git a/src/quick-lint-js/diag/diag-code-list.h b/src/quick-lint-js/diag/diag-code-list.h index 75b10fc81f..0f24005454 100644 --- a/src/quick-lint-js/diag/diag-code-list.h +++ b/src/quick-lint-js/diag/diag-code-list.h @@ -62,12 +62,12 @@ class Compiled_Diag_Code_List { // movable. std::unique_ptr allocator_; - Bump_Vector parsed_diag_code_lists_{ - "parsed_diag_code_lists_", this->allocator_.get()}; + Bump_Vector parsed_diag_code_lists_{"parsed_diag_code_lists_", + this->allocator_.get()}; // Collected errors and warnings: - Bump_Vector unknown_codes_{ - "unknown_codes_", this->allocator_.get()}; + Bump_Vector unknown_codes_{"unknown_codes_", + this->allocator_.get()}; bool has_missing_predicate_error_ = false; }; } diff --git a/src/quick-lint-js/fe/expression.h b/src/quick-lint-js/fe/expression.h index 1e0b852b96..8fe82a5b60 100644 --- a/src/quick-lint-js/fe/expression.h +++ b/src/quick-lint-js/fe/expression.h @@ -162,7 +162,7 @@ class Expression_Arena { using Buffering_Visitor_Ptr = Buffering_Visitor *; template - using Vector = Bump_Vector; + using Vector = Bump_Vector; template static inline constexpr bool is_allocatable = @@ -172,7 +172,7 @@ class Expression_Arena { Expression *make_expression(Args &&... args); template - Array_Ptr make_array(Bump_Vector &&); + Array_Ptr make_array(Bump_Vector &&); template Array_Ptr make_array(T *begin, T *end); @@ -337,7 +337,7 @@ Expression *Expression_Arena::make_expression(Args &&... args) { template inline Expression_Arena::Array_Ptr Expression_Arena::make_array( - Bump_Vector &&elements) { + Bump_Vector &&elements) { QLJS_ASSERT(elements.get_allocator() == &this->allocator_); // NOTE(strager): Adopt the pointer instead of copying. Array_Ptr result(elements.data(), elements.size()); diff --git a/src/quick-lint-js/fe/lex.cpp b/src/quick-lint-js/fe/lex.cpp index 1973613490..661d08e575 100644 --- a/src/quick-lint-js/fe/lex.cpp +++ b/src/quick-lint-js/fe/lex.cpp @@ -1698,8 +1698,8 @@ Lexer::Parsed_Identifier Lexer::parse_identifier_slow( const Char8* private_identifier_begin = is_private_identifier ? &identifier_begin[-1] : identifier_begin; - Bump_Vector normalized( - "parse_identifier_slow normalized", &this->allocator_); + Bump_Vector normalized("parse_identifier_slow normalized", + &this->allocator_); normalized.append(private_identifier_begin, input); Escape_Sequence_List* escape_sequences = diff --git a/src/quick-lint-js/fe/parse-class.cpp b/src/quick-lint-js/fe/parse-class.cpp index 559746aec7..2a35eb9d04 100644 --- a/src/quick-lint-js/fe/parse-class.cpp +++ b/src/quick-lint-js/fe/parse-class.cpp @@ -294,9 +294,8 @@ void Parser::parse_and_visit_class_or_interface_member( this->type == Token_Type::kw_public; } }; - Bump_Vector modifiers = - Bump_Vector("class member modifiers", - &p->temporary_memory_); + Bump_Vector modifiers = + Bump_Vector("class member modifiers", &p->temporary_memory_); // Example: // @@ -323,8 +322,8 @@ void Parser::parse_and_visit_class_or_interface_member( Source_Code_Span name_span; }; - Bump_Vector - overload_signatures{"class overload signatures", &p->temporary_memory_}; + Bump_Vector overload_signatures{ + "class overload signatures", &p->temporary_memory_}; void reset_state_except_overload_signatures() { this->current_member_begin = p->peek().begin; @@ -897,8 +896,8 @@ void Parser::parse_and_visit_class_or_interface_member( // this->overload_signatures then parse the next member. is_possibly_typescript_overload = true; const Char8 *expected_body = p->lexer_.end_of_previous_token(); - Bump_Vector semicolons( - "semicolons", &p->temporary_memory_); + Bump_Vector semicolons("semicolons", + &p->temporary_memory_); while (p->peek().type == Token_Type::semicolon) { semicolons.push_back(p->peek().span()); p->skip(); diff --git a/src/quick-lint-js/fe/parse-expression.cpp b/src/quick-lint-js/fe/parse-expression.cpp index 22799f1280..821bdd1a6b 100644 --- a/src/quick-lint-js/fe/parse-expression.cpp +++ b/src/quick-lint-js/fe/parse-expression.cpp @@ -3763,8 +3763,8 @@ Expression* Parser::parse_jsx_element_or_fragment(Parse_Visitor_Base& v, mismatch = true; } if (mismatch) { - Bump_Vector opening_tag_name_pretty( - "opening_tag_name_pretty", &this->diagnostic_memory_); + Bump_Vector opening_tag_name_pretty("opening_tag_name_pretty", + &this->diagnostic_memory_); if (tag_namespace) { opening_tag_name_pretty += tag_namespace->span().string_view(); opening_tag_name_pretty += u8':'; diff --git a/src/quick-lint-js/fe/parse-statement.cpp b/src/quick-lint-js/fe/parse-statement.cpp index 713b0fef90..a41a1b2d6f 100644 --- a/src/quick-lint-js/fe/parse-statement.cpp +++ b/src/quick-lint-js/fe/parse-statement.cpp @@ -1232,7 +1232,7 @@ void Parser::parse_and_visit_export(Parse_Visitor_Base &v, // NOTE[ambiguous-ambient-statement-in-namespace]. Stacked_Buffering_Visitor exports_visitor = this->buffering_visitor_stack_.push(); - Bump_Vector exported_bad_tokens( + Bump_Vector exported_bad_tokens( "parse_and_visit_export exported_bad_tokens", &this->temporary_memory_); this->parse_and_visit_named_exports( exports_visitor.visitor(), @@ -1595,7 +1595,7 @@ void Parser::parse_and_visit_typescript_generic_parameters( const Char8 *less_end = this->peek().end; this->skip(); - Bump_Vector leading_commas( + Bump_Vector leading_commas( "parse_and_visit_typescript_generic_parameters leading_commas", &this->temporary_memory_); while (this->peek().type == Token_Type::comma) { @@ -1942,7 +1942,7 @@ void Parser::parse_and_visit_function_declaration( Identifier function_name = this->peek().identifier_name(); this->skip(); - Bump_Vector overload_names( + Bump_Vector overload_names( "parse_and_visit_function_declaration overload_names", &this->temporary_memory_); @@ -4626,7 +4626,7 @@ void Parser::parse_and_visit_named_exports_for_typescript_type_only_import( void Parser::parse_and_visit_named_exports( Parse_Visitor_Base &v, std::optional typescript_type_only_keyword, - Bump_Vector *out_exported_bad_tokens) { + Bump_Vector *out_exported_bad_tokens) { QLJS_ASSERT(this->peek().type == Token_Type::left_curly); this->skip(); diff --git a/src/quick-lint-js/fe/parse.cpp b/src/quick-lint-js/fe/parse.cpp index fb7417949b..d3e15b6eb1 100644 --- a/src/quick-lint-js/fe/parse.cpp +++ b/src/quick-lint-js/fe/parse.cpp @@ -192,8 +192,8 @@ void Parser::check_jsx_attribute(const Identifier& attribute_name) { bool name_has_upper = any_of(name, isupper); if (!name_has_upper && is_event_attribute) { - Bump_Vector fixed_name( - "check_jsx_attribute fixed_name", &this->diagnostic_memory_); + Bump_Vector fixed_name("check_jsx_attribute fixed_name", + &this->diagnostic_memory_); fixed_name += name; fixed_name[2] = toupper(fixed_name[2]); this->diag_reporter_->report(Diag_JSX_Event_Attribute_Should_Be_Camel_Case{ diff --git a/src/quick-lint-js/fe/parse.h b/src/quick-lint-js/fe/parse.h index 214d93dbbc..0e028d7bd8 100644 --- a/src/quick-lint-js/fe/parse.h +++ b/src/quick-lint-js/fe/parse.h @@ -566,7 +566,7 @@ class Parser { void parse_and_visit_named_exports( Parse_Visitor_Base &v, std::optional typescript_type_only_keyword, - Bump_Vector *out_exported_bad_tokens); + Bump_Vector *out_exported_bad_tokens); void parse_and_visit_variable_declaration_statement( Parse_Visitor_Base &v, diff --git a/src/quick-lint-js/fe/token.h b/src/quick-lint-js/fe/token.h index 7c1a61fe8a..6f61d76284 100644 --- a/src/quick-lint-js/fe/token.h +++ b/src/quick-lint-js/fe/token.h @@ -289,7 +289,7 @@ enum class Token_Type { const char* to_string(Token_Type); std::ostream& operator<<(std::ostream&, Token_Type); -using Escape_Sequence_List = Bump_Vector; +using Escape_Sequence_List = Bump_Vector; struct Token { Identifier identifier_name() const; diff --git a/src/quick-lint-js/i18n/po-parser.cpp b/src/quick-lint-js/i18n/po-parser.cpp index ab209a0dfe..c809b24bbc 100644 --- a/src/quick-lint-js/i18n/po-parser.cpp +++ b/src/quick-lint-js/i18n/po-parser.cpp @@ -131,8 +131,7 @@ class PO_Parser { this->fatal(); } this->input_ += 1; - Bump_Vector decoded("parse_string", - this->allocator_); + Bump_Vector decoded("parse_string", this->allocator_); for (;;) { switch (*this->input_) { case u8'"': { @@ -219,8 +218,7 @@ class PO_Parser { const CLI_Locator* locator_; Monotonic_Allocator* allocator_; - Bump_Vector entries_{"PO_Parser::entries", - this->allocator_}; + Bump_Vector entries_{"PO_Parser::entries", this->allocator_}; bool is_next_entry_fuzzy_ = false; }; diff --git a/src/quick-lint-js/i18n/translation-table-compiler.cpp b/src/quick-lint-js/i18n/translation-table-compiler.cpp index 4966f9cbce..e4a843267d 100644 --- a/src/quick-lint-js/i18n/translation-table-compiler.cpp +++ b/src/quick-lint-js/i18n/translation-table-compiler.cpp @@ -36,7 +36,7 @@ struct String_Table { } private: - Bump_Vector strings_; + Bump_Vector strings_; }; } @@ -78,7 +78,7 @@ Compiled_Translation_Table compile_translation_table( Span keys = untranslated_strings; { - Bump_Vector locale_names( + Bump_Vector locale_names( "compile_translation_table locale_names", allocator); for (const PO_File& file : files) { locale_names.push_back(file.locale); @@ -182,7 +182,7 @@ Compiled_Translation_Table compile_translation_table( Span get_all_untranslated(Span files, Monotonic_Allocator* allocator) { - Bump_Vector all_untranslated( + Bump_Vector all_untranslated( "get_all_untranslated all_untranslated", allocator); auto add_untranslated = [&](String8_View untranslated) -> void { bool is_duplicate = contains(all_untranslated, untranslated); diff --git a/src/quick-lint-js/i18n/translation.cpp b/src/quick-lint-js/i18n/translation.cpp index 8f984a64a9..673a494fb3 100644 --- a/src/quick-lint-js/i18n/translation.cpp +++ b/src/quick-lint-js/i18n/translation.cpp @@ -26,8 +26,7 @@ Translator qljs_messages; namespace { Span split_on(const char* s, char separator, Monotonic_Allocator* allocator) { - Bump_Vector locales("locales", - allocator); + Bump_Vector locales("locales", allocator); for (;;) { const char* sep = std::strchr(s, separator); if (sep) { @@ -65,8 +64,7 @@ Span get_user_locale_preferences( // TODO(strager): Determine the language using macOS' and Windows' native // APIs. See GNU gettext's _nl_language_preferences_default. - Bump_Vector locales("locales", - allocator); + Bump_Vector locales("locales", allocator); locales.push_back(locale); return locales.release_to_span(); } diff --git a/src/quick-lint-js/io/event-loop-poll.cpp b/src/quick-lint-js/io/event-loop-poll.cpp index 8910816313..6f1c7988b9 100644 --- a/src/quick-lint-js/io/event-loop-poll.cpp +++ b/src/quick-lint-js/io/event-loop-poll.cpp @@ -74,9 +74,9 @@ Event_Loop_Poll::~Event_Loop_Poll() { delete this->impl_; } void Event_Loop_Poll::run() { Monotonic_Allocator allocator("Event_Loop_Poll"); // events[i] corresponds to event_registered_events[i]. - Bump_Vector<::pollfd, Monotonic_Allocator> events("events", &allocator); - Bump_Vector - event_registered_events("event_registered_events", &allocator); + Bump_Vector<::pollfd> events("events", &allocator); + Bump_Vector event_registered_events( + "event_registered_events", &allocator); while (!this->is_stop_requested()) { events.clear(); diff --git a/src/quick-lint-js/lsp/lsp-workspace-configuration.h b/src/quick-lint-js/lsp/lsp-workspace-configuration.h index 023d9a9c96..e203717a11 100644 --- a/src/quick-lint-js/lsp/lsp-workspace-configuration.h +++ b/src/quick-lint-js/lsp/lsp-workspace-configuration.h @@ -61,7 +61,7 @@ class LSP_Workspace_Configuration { Item* find_item(String8_View name); bool set_item(Item&, ::simdjson::ondemand::value); - Bump_Vector items_; + Bump_Vector items_; }; } diff --git a/src/quick-lint-js/port/child-process.cpp b/src/quick-lint-js/port/child-process.cpp index dbb97d9218..5510387e18 100644 --- a/src/quick-lint-js/port/child-process.cpp +++ b/src/quick-lint-js/port/child-process.cpp @@ -86,8 +86,7 @@ Run_Program_Result run_program(Span command) { Run_Program_Result run_program(Span command, Run_Program_Options options) { Monotonic_Allocator allocator("run_program"); - Bump_Vector command_raw("command_raw", - &allocator); + Bump_Vector command_raw("command_raw", &allocator); for (const std::string& arg : command) { command_raw.push_back(arg.c_str()); } @@ -123,7 +122,7 @@ Run_Program_Result run_program(Span command, } Monotonic_Allocator allocator("run_program"); - Bump_Vector argv("argv", &allocator); + Bump_Vector argv("argv", &allocator); for (const char* arg : command) { argv.push_back(const_cast(arg)); } diff --git a/src/quick-lint-js/reflection/cxx-parser.cpp b/src/quick-lint-js/reflection/cxx-parser.cpp index da63ad5a14..b1ea8980cd 100644 --- a/src/quick-lint-js/reflection/cxx-parser.cpp +++ b/src/quick-lint-js/reflection/cxx-parser.cpp @@ -233,8 +233,8 @@ String8_View CXX_Lexer::lex_string_literal() { QLJS_ASSERT(*this->input_ == u8'"'); this->input_ += 1; - Bump_Vector decoded( - "CXX_Lexer::lex_string_literal", &this->decoded_string_allocator_); + Bump_Vector decoded("CXX_Lexer::lex_string_literal", + &this->decoded_string_allocator_); for (;;) { switch (*this->input_) { case u8'"': { diff --git a/src/quick-lint-js/reflection/cxx-parser.h b/src/quick-lint-js/reflection/cxx-parser.h index 6b92d99b2d..9ccd4005f0 100644 --- a/src/quick-lint-js/reflection/cxx-parser.h +++ b/src/quick-lint-js/reflection/cxx-parser.h @@ -198,10 +198,10 @@ class CXX_Diagnostic_Types_Parser : private CXX_Parser_Base { using Base::fatal_at; Monotonic_Allocator allocator_{"CXX_Diagnostic_Types_Parser"}; - Bump_Vector parsed_types{ - "parsed_types", &this->allocator_}; - Bump_Vector reserved_codes{ - "reserved_codes", &this->allocator_}; + Bump_Vector parsed_types{"parsed_types", + &this->allocator_}; + Bump_Vector reserved_codes{"reserved_codes", + &this->allocator_}; }; // Precondition: variables.size() <= 4 diff --git a/test/quick-lint-js/tjson.cpp b/test/quick-lint-js/tjson.cpp index 6dceefbc81..f2b078accb 100644 --- a/test/quick-lint-js/tjson.cpp +++ b/test/quick-lint-js/tjson.cpp @@ -98,8 +98,8 @@ TJSON_Value TJSON_Value::operator[](std::size_t index) const { std::optional> TJSON_Value::try_get_array() const { TJSON::Impl* tjson_impl = this->impl_->tjson_impl; - Bump_Vector items( - "TJSON_Value::try_get_array items", &tjson_impl->allocator); + Bump_Vector items("TJSON_Value::try_get_array items", + &tjson_impl->allocator); ::simdjson::dom::array array; if (this->impl_->value.get(array) != ::simdjson::SUCCESS) { return std::nullopt; diff --git a/test/test-vector.cpp b/test/test-vector.cpp index 1f928fb643..0d40c099d8 100644 --- a/test/test-vector.cpp +++ b/test/test-vector.cpp @@ -16,7 +16,7 @@ namespace quick_lint_js { namespace { TEST(Test_Bump_Vector, empty) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); EXPECT_TRUE(v.empty()); EXPECT_EQ(v.size(), 0); EXPECT_EQ(v.capacity(), 0); @@ -24,7 +24,7 @@ TEST(Test_Bump_Vector, empty) { TEST(Test_Bump_Vector, append_into_reserved_memory) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.reserve(2); EXPECT_EQ(v.capacity(), 2); EXPECT_EQ(v.size(), 0); @@ -43,7 +43,7 @@ TEST(Test_Bump_Vector, append_into_reserved_memory) { TEST(Test_Bump_Vector, reserve_0_does_nothing) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.reserve(0); EXPECT_EQ(v.capacity(), 0); EXPECT_EQ(v.size(), 0); @@ -59,7 +59,7 @@ TEST(Test_Bump_Vector, reserve_0_does_nothing) { TEST(Test_Bump_Vector, append_into_new_memory) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); EXPECT_EQ(v.capacity(), 0); EXPECT_EQ(v.size(), 0); @@ -76,7 +76,7 @@ TEST(Test_Bump_Vector, append_into_new_memory) { TEST(Test_Bump_Vector, growing_allocation_in_place) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.reserve(2); v.emplace_back(100); @@ -92,7 +92,7 @@ TEST(Test_Bump_Vector, growing_allocation_in_place) { TEST(Test_Bump_Vector, growing_allocation_by_copy) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.reserve(2); v.emplace_back(100); @@ -118,7 +118,7 @@ TEST(Test_Bump_Vector, growing_allocation_by_copy) { TEST(Test_Bump_Vector, resize_allows_same_size) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.emplace_back(100); v.emplace_back(200); std::uintptr_t old_v_data_pointer = @@ -137,7 +137,7 @@ TEST(Test_Bump_Vector, resize_allows_same_size) { TEST(Test_Bump_Vector, resize_allows_shrinking) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.emplace_back(100); v.emplace_back(200); v.emplace_back(300); @@ -158,7 +158,7 @@ TEST(Test_Bump_Vector, resize_allows_shrinking) { TEST(Test_Bump_Vector, resize_allows_growing_within_capacity) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.emplace_back(100); v.emplace_back(200); std::uintptr_t old_v_data_pointer = @@ -179,7 +179,7 @@ TEST(Test_Bump_Vector, resize_allows_growing_within_capacity) { TEST(Test_Bump_Vector, resize_allows_growing_outside_capacity) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.emplace_back(100); v.emplace_back(200); @@ -195,7 +195,7 @@ TEST(Test_Bump_Vector, resize_allows_growing_outside_capacity) { TEST(Test_Bump_Vector, pop_back_shrinks_vector) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.push_back(100); v.push_back(200); v.push_back(300); @@ -207,7 +207,7 @@ TEST(Test_Bump_Vector, pop_back_shrinks_vector) { TEST(Test_Bump_Vector, pop_back_then_push_back_reuses_memory) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.push_back(100); v.push_back(200); v.push_back(300); @@ -224,17 +224,17 @@ TEST(Test_Bump_Vector, pop_back_then_push_back_reuses_memory) { TEST(Test_Bump_Vector, move_constructing_clears_old_vector) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.emplace_back(100); v.emplace_back(200); - Bump_Vector v2(std::move(v)); + Bump_Vector v2(std::move(v)); EXPECT_THAT(v, IsEmpty()); } TEST(Test_Bump_Vector, move_constructor_preserves_pointers) { Linked_Bump_Allocator alloc("test"); - Bump_Vector v("test", &alloc); + Bump_Vector v("test", &alloc); v.emplace_back(100); v.emplace_back(200); @@ -243,7 +243,7 @@ TEST(Test_Bump_Vector, move_constructor_preserves_pointers) { Bump_Vector_Size old_v_capacity = v.capacity(); Bump_Vector_Size old_v_size = v.size(); - Bump_Vector v2(std::move(v)); + Bump_Vector v2(std::move(v)); EXPECT_EQ(reinterpret_cast(v2.data()), old_v_data_pointer); EXPECT_EQ(v2.capacity(), old_v_capacity); diff --git a/tools/compile-translations.cpp b/tools/compile-translations.cpp index e34ec6d8b9..54d654b3a6 100644 --- a/tools/compile-translations.cpp +++ b/tools/compile-translations.cpp @@ -39,7 +39,7 @@ struct String_Table { // Copies the string. explicit Entry(String8_View string, Monotonic_Allocator* allocator); - Bump_Vector origin_file_paths; + Bump_Vector origin_file_paths; String8_View string; }; @@ -125,7 +125,7 @@ int main(int argc, char** argv) { write_messages_po_template(string_table, output_messages_pot_path); Monotonic_Allocator allocator("main"); - Bump_Vector po_files("PO files", &allocator); + Bump_Vector po_files("PO files", &allocator); for (const char* po_file_path : po_file_paths) { po_files.push_back(PO_File{ .locale = po_path_to_locale_name(po_file_path), @@ -484,7 +484,7 @@ void write_translation_test_header( Output_Stream& out) { Monotonic_Allocator allocator("write_translation_test_header"); - Bump_Vector locale_names( + Bump_Vector locale_names( "compile_translation_table locale_names", &allocator); for (const PO_File& file : po_files) { locale_names.push_back(file.locale); diff --git a/tools/generate-trace-sources.cpp b/tools/generate-trace-sources.cpp index 3bdb51bb18..cce75c810f 100644 --- a/tools/generate-trace-sources.cpp +++ b/tools/generate-trace-sources.cpp @@ -141,8 +141,8 @@ class CXX_Trace_Types_Parser : public CXX_Parser_Base { this->skip(); this->expect_skip(CXX_Token_Type::less); this->expect_skip(u8"class"_sv); - Bump_Vector template_parameters( - "template_parameters", &this->memory_); + Bump_Vector template_parameters("template_parameters", + &this->memory_); template_parameters.emplace_back(this->expect_skip_identifier()); this->expect_skip(CXX_Token_Type::greater); s.template_parameters = template_parameters.release_to_span(); @@ -154,8 +154,7 @@ class CXX_Trace_Types_Parser : public CXX_Parser_Base { s.ctf_name = this->cxx_name_to_ctf_name(s.cxx_name); this->expect_skip(CXX_Token_Type::left_curly); - Bump_Vector members( - "members", &this->memory_); + Bump_Vector members("members", &this->memory_); while (!this->peek_is(CXX_Token_Type::right_curly)) { if (this->peek_is(u8"static"_sv)) { // static constexpr std::uint8_t id = 0x03; @@ -292,8 +291,7 @@ class CXX_Trace_Types_Parser : public CXX_Parser_Base { e.underlying_cxx_type = this->expect_skip_identifier(); this->expect_skip(CXX_Token_Type::left_curly); - Bump_Vector members( - "members", &this->memory_); + Bump_Vector members("members", &this->memory_); while (!this->peek_is(CXX_Token_Type::right_curly)) { // name = 42, Parsed_Enum_Member& member = members.emplace_back(); @@ -394,8 +392,7 @@ class CXX_Trace_Types_Parser : public CXX_Parser_Base { } Monotonic_Allocator memory_{"CXX_Trace_Types_Parser"}; - Bump_Vector declarations{ - "declarations", &this->memory_}; + Bump_Vector declarations{"declarations", &this->memory_}; }; void write_010_editor_template(CXX_Trace_Types_Parser& types,