From 8e813a9b8d1b240ed633297db6217937aa028d28 Mon Sep 17 00:00:00 2001 From: Dr_rOot Date: Fri, 20 Nov 2026 10:02:19 +0800 Subject: [PATCH] perf(bt): append validated torrent output mappings in place --- src/Option.cc | 9 +++++++++ src/Option.h | 1 + src/OptionHandlerImpl.cc | 5 +---- test/OptionTest.cc | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Option.cc b/src/Option.cc index fb555bee44..71305d3435 100644 --- a/src/Option.cc +++ b/src/Option.cc @@ -80,6 +80,15 @@ void Option::put(PrefPtr pref, const std::string& value) table_[pref->i] = value; } +void Option::append(PrefPtr pref, const std::string& value, + const std::string& delim) +{ + if (!definedLocal(pref)) { + put(pref, get(pref)); + } + table_[pref->i].append(value).append(delim); +} + bool Option::defined(PrefPtr pref) const { return bitfield::test(use_, use_.size() * 8, pref->i) || diff --git a/src/Option.h b/src/Option.h index 76193084f4..ea7d2dab81 100644 --- a/src/Option.h +++ b/src/Option.h @@ -58,6 +58,7 @@ class Option { Option& operator=(const Option& option); void put(PrefPtr pref, const std::string& value); + void append(PrefPtr pref, const std::string& value, const std::string& delim); // Returns true if name is defined. Otherwise returns false. Note // that even if the value is a empty string, this method returns // true. If option is not defined in this object and parent_ is not diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index 6214e84b30..76ca60e11e 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -347,10 +347,7 @@ void IndexOutOptionHandler::parseArg(Option& option, { // See optarg is in the format of "INDEX=PATH" util::parseIndexPath(optarg); - std::string value = option.get(pref_); - value += optarg; - value += "\n"; - option.put(pref_, value); + option.append(pref_, optarg, "\n"); } std::string IndexOutOptionHandler::createPossibleValuesString() const diff --git a/test/OptionTest.cc b/test/OptionTest.cc index b8f39b8130..ce9429c821 100644 --- a/test/OptionTest.cc +++ b/test/OptionTest.cc @@ -1,4 +1,5 @@ #include "Option.h" +#include "OptionHandlerImpl.h" #include @@ -12,6 +13,7 @@ class OptionTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(OptionTest); CPPUNIT_TEST(testPutAndGet); + CPPUNIT_TEST(testAppendInheritedMappings); CPPUNIT_TEST(testPutAndGetAsInt); CPPUNIT_TEST(testPutAndGetAsDouble); CPPUNIT_TEST(testDefined); @@ -26,6 +28,7 @@ class OptionTest : public CppUnit::TestFixture { void setUp() {} void testPutAndGet(); + void testAppendInheritedMappings(); void testPutAndGetAsInt(); void testPutAndGetAsDouble(); void testDefined(); @@ -37,6 +40,27 @@ class OptionTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_REGISTRATION(OptionTest); +void OptionTest::testAppendInheritedMappings() +{ + auto parent = std::make_shared