Skip to content

Commit

Permalink
treewide: use fmt::to_string instead of std version
Browse files Browse the repository at this point in the history
The former is faster. More info: fmtlib/fmt#326

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 31, 2021
1 parent 1a02ea0 commit 7c59528
Show file tree
Hide file tree
Showing 31 changed files with 124 additions and 124 deletions.
4 changes: 2 additions & 2 deletions src/cds_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::shared_ptr<CdsObject> CdsObject::createObject(unsigned int objectType)
} else if (IS_CDS_ITEM(objectType)) {
obj = std::make_shared<CdsItem>();
} else {
throw_std_runtime_error("invalid object type: " + std::to_string(objectType));
throw_std_runtime_error("invalid object type: " + fmt::to_string(objectType));
}
return obj;
}
Expand Down Expand Up @@ -243,5 +243,5 @@ std::string CdsObject::mapObjectType(unsigned int type)
return STRING_OBJECT_TYPE_ITEM;
if (IS_CDS_ITEM_EXTERNAL_URL(type))
return STRING_OBJECT_TYPE_EXTERNAL_URL;
throw_std_runtime_error("illegal objectType: " + std::to_string(type));
throw_std_runtime_error("illegal objectType: " + fmt::to_string(type));
}
18 changes: 9 additions & 9 deletions src/config/config_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ std::string ConfigGenerator::generate(const fs::path& userHome, const fs::path&
auto config = init();

config->append_attribute("version") = CONFIG_XML_VERSION;
config->append_attribute("xmlns") = (XML_XMLNS + std::to_string(CONFIG_XML_VERSION)).c_str();
config->append_attribute("xmlns") = (XML_XMLNS + fmt::to_string(CONFIG_XML_VERSION)).c_str();
config->append_attribute("xmlns:xsi") = XML_XMLNS_XSI;
config->append_attribute("xsi:schemaLocation") = (std::string(XML_XMLNS) + std::to_string(CONFIG_XML_VERSION) + " " + XML_XMLNS + std::to_string(CONFIG_XML_VERSION) + ".xsd").c_str();
config->append_attribute("xsi:schemaLocation") = (std::string(XML_XMLNS) + fmt::to_string(CONFIG_XML_VERSION) + " " + XML_XMLNS + fmt::to_string(CONFIG_XML_VERSION) + ".xsd").c_str();

auto docinfo = config->append_child(pugi::node_comment);
docinfo.set_value("\n\
Expand Down Expand Up @@ -185,7 +185,7 @@ void ConfigGenerator::generateServer(const fs::path& userHome, const fs::path& c
("\n\
How frequently (in seconds) to send ssdp:alive advertisements.\n\
Minimum alive value accepted is: "
+ std::to_string(ALIVE_INTERVAL_MIN) + "\n\n\
+ fmt::to_string(ALIVE_INTERVAL_MIN) + "\n\n\
The advertisement will be sent every (A/2)-30 seconds,\n\
and will have a cache-control max-age of A where A is\n\
the value configured here. Ex: A value of 62 will result\n\
Expand Down Expand Up @@ -375,9 +375,9 @@ void ConfigGenerator::generateTranscoding()
setValue(agent, ATTR_TRANSCODING_PROFILES_PROFLE_AGENT_ARGS, "-y -i %in -f mp3 %out");

auto buffer = setValue(fmt::format("{}/{}/", profileTag, ConfigManager::mapConfigOption(ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER)), "", true);
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_SIZE, std::to_string(DEFAULT_AUDIO_BUFFER_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_CHUNK, std::to_string(DEFAULT_AUDIO_CHUNK_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_FILL, std::to_string(DEFAULT_AUDIO_FILL_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_SIZE, fmt::to_string(DEFAULT_AUDIO_BUFFER_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_CHUNK, fmt::to_string(DEFAULT_AUDIO_CHUNK_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_FILL, fmt::to_string(DEFAULT_AUDIO_FILL_SIZE));

auto vlcmpeg = setValue(fmt::format("{}/", profileTag), "", true);
setValue(vlcmpeg, ATTR_TRANSCODING_PROFILES_PROFLE_NAME, "vlcmpeg");
Expand All @@ -393,9 +393,9 @@ void ConfigGenerator::generateTranscoding()
setValue(agent, ATTR_TRANSCODING_PROFILES_PROFLE_AGENT_ARGS, "-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit");

buffer = setValue(fmt::format("{}/{}/", profileTag, ConfigManager::mapConfigOption(ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER)), "", true);
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_SIZE, std::to_string(DEFAULT_VIDEO_BUFFER_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_CHUNK, std::to_string(DEFAULT_VIDEO_CHUNK_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_FILL, std::to_string(DEFAULT_VIDEO_FILL_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_SIZE, fmt::to_string(DEFAULT_VIDEO_BUFFER_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_CHUNK, fmt::to_string(DEFAULT_VIDEO_CHUNK_SIZE));
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_FILL, fmt::to_string(DEFAULT_VIDEO_FILL_SIZE));
}

void ConfigGenerator::generateUdn()
Expand Down
16 changes: 8 additions & 8 deletions src/config/config_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ const std::vector<std::shared_ptr<ConfigSetup>> ConfigManager::complexOptions =
DEFAULT_ATRAILERS_REFRESH),
std::make_shared<ConfigEnumSetup<std::string>>(CFG_ONLINE_CONTENT_ATRAILERS_RESOLUTION,
"/import/online-content/AppleTrailers/attribute::resolution", "config-online.html#appletrailers",
std::to_string(DEFAULT_ATRAILERS_RESOLUTION).c_str(),
fmt::to_string(DEFAULT_ATRAILERS_RESOLUTION).c_str(),
std::map<std::string, std::string>({ { "640", "640" }, { "720", "720p" }, { "720p", "720p" } })),
#endif

Expand Down Expand Up @@ -988,7 +988,7 @@ void ConfigManager::load(const fs::path& userHome)

// now get the option list for the drop down menu
auto menu_opts = setOption(root, CFG_SERVER_UI_ITEMS_PER_PAGE_DROPDOWN)->getArrayOption();
if (std::none_of(menu_opts.begin(), menu_opts.end(), [=](const auto& s) { return s == std::to_string(def_ipp); }))
if (std::none_of(menu_opts.begin(), menu_opts.end(), [=](const auto& s) { return s == fmt::to_string(def_ipp); }))
throw std::runtime_error("Error in config file: at least one <option> "
"under <items-per-page> must match the "
"<items-per-page default=\"\" /> attribute");
Expand All @@ -1006,7 +1006,7 @@ void ConfigManager::load(const fs::path& userHome)
setOption(root, CFG_IMPORT_FOLLOW_SYMLINKS);
setOption(root, CFG_IMPORT_MAPPINGS_IGNORE_UNKNOWN_EXTENSIONS);
bool csens = setOption(root, CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_CASE_SENSITIVE)->getBoolOption();
args["tolower"] = std::to_string(!csens);
args["tolower"] = fmt::to_string(!csens);
setOption(root, CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_LIST, &args);
args.clear();
setOption(root, CFG_IMPORT_MAPPINGS_MIMETYPE_TO_CONTENTTYPE_LIST);
Expand Down Expand Up @@ -1137,9 +1137,9 @@ void ConfigManager::load(const fs::path& userHome)
}

co = findConfigSetup(CFG_IMPORT_SCRIPTING_IMPORT_SCRIPT);
args["isFile"] = std::to_string(true);
args["mustExist"] = std::to_string(layoutType == "js");
args["notEmpty"] = std::to_string(layoutType == "js");
args["isFile"] = fmt::to_string(true);
args["mustExist"] = fmt::to_string(layoutType == "js");
args["notEmpty"] = fmt::to_string(layoutType == "js");
co->setDefaultValue(dataDir / DEFAULT_JS_DIR / DEFAULT_IMPORT_SCRIPT);
co->makeOption(root, self, &args);
args.clear();
Expand All @@ -1148,7 +1148,7 @@ void ConfigManager::load(const fs::path& userHome)
#endif
co = findConfigSetup(CFG_SERVER_PORT);
// 0 means, that the SDK will any free port itself
co->makeOption((port == 0) ? co->getXmlContent(root) : std::to_string(port), self);
co->makeOption((port == 0) ? co->getXmlContent(root) : fmt::to_string(port), self);

setOption(root, CFG_SERVER_ALIVE_INTERVAL);
setOption(root, CFG_IMPORT_MAPPINGS_MIMETYPE_TO_UPNP_CLASS_LIST);
Expand Down Expand Up @@ -1285,7 +1285,7 @@ void ConfigManager::load(const fs::path& userHome)
int atrailers_refresh = setOption(root, CFG_ONLINE_CONTENT_ATRAILERS_REFRESH)->getIntOption();

co = findConfigSetup(CFG_ONLINE_CONTENT_ATRAILERS_PURGE_AFTER);
co->makeOption(std::to_string(atrailers_refresh), self);
co->makeOption(fmt::to_string(atrailers_refresh), self);

setOption(root, CFG_ONLINE_CONTENT_ATRAILERS_UPDATE_AT_START);
setOption(root, CFG_ONLINE_CONTENT_ATRAILERS_RESOLUTION);
Expand Down
22 changes: 11 additions & 11 deletions src/config/config_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,31 +361,31 @@ std::shared_ptr<ConfigOption> ConfigIntSetup::newOption(int optValue)
bool ConfigIntSetup::CheckSqlLiteSyncValue(std::string& value)
{
auto temp_int = 0;
if (value == "off" || value == std::to_string(MT_SQLITE_SYNC_OFF))
if (value == "off" || value == fmt::to_string(MT_SQLITE_SYNC_OFF))
temp_int = MT_SQLITE_SYNC_OFF;
else if (value == "normal" || value == std::to_string(MT_SQLITE_SYNC_NORMAL))
else if (value == "normal" || value == fmt::to_string(MT_SQLITE_SYNC_NORMAL))
temp_int = MT_SQLITE_SYNC_NORMAL;
else if (value == "full" || value == std::to_string(MT_SQLITE_SYNC_FULL))
else if (value == "full" || value == fmt::to_string(MT_SQLITE_SYNC_FULL))
temp_int = MT_SQLITE_SYNC_FULL;
else
return false;
value.assign(std::to_string(temp_int));
value.assign(fmt::to_string(temp_int));
return true;
}

bool ConfigIntSetup::CheckProfileNumberValue(std::string& value)
{
auto temp_int = 0;
if (value == "source" || value == std::to_string(SOURCE))
if (value == "source" || value == fmt::to_string(SOURCE))
temp_int = SOURCE;
else if (value == "off" || value == std::to_string(OFF))
else if (value == "off" || value == fmt::to_string(OFF))
temp_int = OFF;
else {
temp_int = std::stoi(value);
if (temp_int <= 0)
return false;
}
value.assign(std::to_string(temp_int));
value.assign(fmt::to_string(temp_int));
return true;
}

Expand Down Expand Up @@ -658,10 +658,10 @@ bool ConfigArraySetup::InitItemsPerPage(const pugi::xml_node& value, std::vector
{
// create default structure
if (std::distance(value.begin(), value.end()) == 0) {
result.emplace_back(std::to_string(DEFAULT_ITEMS_PER_PAGE_1));
result.emplace_back(std::to_string(DEFAULT_ITEMS_PER_PAGE_2));
result.emplace_back(std::to_string(DEFAULT_ITEMS_PER_PAGE_3));
result.emplace_back(std::to_string(DEFAULT_ITEMS_PER_PAGE_4));
result.emplace_back(fmt::to_string(DEFAULT_ITEMS_PER_PAGE_1));
result.emplace_back(fmt::to_string(DEFAULT_ITEMS_PER_PAGE_2));
result.emplace_back(fmt::to_string(DEFAULT_ITEMS_PER_PAGE_3));
result.emplace_back(fmt::to_string(DEFAULT_ITEMS_PER_PAGE_4));
} else {
// create the array from either user settings
for (const auto& it : value.select_nodes(node_name)) {
Expand Down
10 changes: 5 additions & 5 deletions src/config/config_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,38 +335,38 @@ class ConfigIntSetup : public ConfigSetup {
: ConfigSetup(option, xpath, help)

{
this->defaultValue = std::to_string(0);
this->defaultValue = fmt::to_string(0);
}

ConfigIntSetup(config_option_t option, const char* xpath, const char* help, int defaultValue)
: ConfigSetup(option, xpath, help)

{
this->defaultValue = std::to_string(defaultValue);
this->defaultValue = fmt::to_string(defaultValue);
}

ConfigIntSetup(config_option_t option, const char* xpath, const char* help, IntCheckFunction check)
: ConfigSetup(option, xpath, help)
, valueCheck(check)

{
this->defaultValue = std::to_string(0);
this->defaultValue = fmt::to_string(0);
}

ConfigIntSetup(config_option_t option, const char* xpath, const char* help, int defaultValue, IntCheckFunction check)
: ConfigSetup(option, xpath, help)
, valueCheck(check)

{
this->defaultValue = std::to_string(defaultValue);
this->defaultValue = fmt::to_string(defaultValue);
}

ConfigIntSetup(config_option_t option, const char* xpath, const char* help, int defaultValue, int minValue, IntMinFunction check)
: ConfigSetup(option, xpath, help)
, minCheck(check)
, minValue(minValue)
{
this->defaultValue = std::to_string(defaultValue);
this->defaultValue = fmt::to_string(defaultValue);
}

ConfigIntSetup(config_option_t option, const char* xpath, const char* help, const char* defaultValue, IntCheckFunction check = nullptr)
Expand Down
4 changes: 2 additions & 2 deletions src/content/content_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,8 @@ int ContentManager::addContainerChain(const std::string& chain, const std::strin
fanart = std::find_if(origResources.begin(), origResources.end(), [=](const auto& res) { return res->isMetaResource(ID3_ALBUM_ART); });
if (fanart != origResources.end()) {
if ((*fanart)->getAttribute(R_RESOURCE_FILE).empty()) {
(*fanart)->addAttribute(R_FANART_OBJ_ID, std::to_string(origObj->getID()));
(*fanart)->addAttribute(R_FANART_RES_ID, std::to_string(fanart - origResources.begin()));
(*fanart)->addAttribute(R_FANART_OBJ_ID, fmt::to_string(origObj->getID()));
(*fanart)->addAttribute(R_FANART_RES_ID, fmt::to_string(fanart - origResources.begin()));
}
container->addResource(*fanart);
}
Expand Down
6 changes: 3 additions & 3 deletions src/content/onlineservice/atrailers_content_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::shared_ptr<CdsObject> ATrailersContentHandler::getObject(const pugi::xml_no
item->setMimeType(trailer_mimetype);
resource->addAttribute(R_PROTOCOLINFO, renderProtocolInfo(trailer_mimetype));

item->setAuxData(ONLINE_SERVICE_AUX_ID, std::to_string(OS_ATrailers));
item->setAuxData(ONLINE_SERVICE_AUX_ID, fmt::to_string(OS_ATrailers));

temp = trailer.attribute("id").as_string();
if (temp.empty()) {
Expand All @@ -114,7 +114,7 @@ std::shared_ptr<CdsObject> ATrailersContentHandler::getObject(const pugi::xml_no
return nullptr;
}

temp = std::to_string(OnlineService::getDatabasePrefix(OS_ATrailers)) + temp;
temp = fmt::to_string(OnlineService::getDatabasePrefix(OS_ATrailers)) + temp;
item->setServiceID(temp);

auto preview = trailer.child("preview");
Expand Down Expand Up @@ -220,7 +220,7 @@ std::shared_ptr<CdsObject> ATrailersContentHandler::getObject(const pugi::xml_no

struct timespec ts;
getTimespecNow(&ts);
item->setAuxData(ONLINE_SERVICE_LAST_UPDATE, std::to_string(ts.tv_sec));
item->setAuxData(ONLINE_SERVICE_LAST_UPDATE, fmt::to_string(ts.tv_sec));

item->setFlag(OBJECT_FLAG_ONLINE_SERVICE);
try {
Expand Down
4 changes: 2 additions & 2 deletions src/content/onlineservice/sopcast_content_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::shared_ptr<CdsObject> SopCastContentHandler::getObject(const std::string& g
item->addResource(resource);

item->setAuxData(ONLINE_SERVICE_AUX_ID,
std::to_string(OS_SopCast));
fmt::to_string(OS_SopCast));

item->setAuxData(SOPCAST_AUXDATA_GROUP, groupName);

Expand Down Expand Up @@ -208,7 +208,7 @@ std::shared_ptr<CdsObject> SopCastContentHandler::getObject(const std::string& g

struct timespec ts;
getTimespecNow(&ts);
item->setAuxData(ONLINE_SERVICE_LAST_UPDATE, std::to_string(ts.tv_sec));
item->setAuxData(ONLINE_SERVICE_LAST_UPDATE, fmt::to_string(ts.tv_sec));
item->setFlag(OBJECT_FLAG_PROXY_URL);
item->setFlag(OBJECT_FLAG_ONLINE_SERVICE);

Expand Down
2 changes: 1 addition & 1 deletion src/content/scripting/js_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ duk_ret_t js_addCdsObject(duk_context* ctx)
cm->addObject(cds_obj);

/* setting object ID as return value */
std::string tmp = std::to_string(parentId);
std::string tmp = fmt::to_string(parentId);
duk_push_string(ctx, tmp.c_str());
return 1;
} catch (const ServerShutdownException& se) {
Expand Down
4 changes: 2 additions & 2 deletions src/content/scripting/script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void Script::cdsObject2dukObject(const std::shared_ptr<CdsObject>& obj)
}

if (std::static_pointer_cast<CdsItem>(obj)->getTrackNumber() > 0)
setProperty(MetadataHandler::getMetaFieldName(M_TRACKNUMBER), std::to_string(std::static_pointer_cast<CdsItem>(obj)->getTrackNumber()));
setProperty(MetadataHandler::getMetaFieldName(M_TRACKNUMBER), fmt::to_string(std::static_pointer_cast<CdsItem>(obj)->getTrackNumber()));

duk_put_prop_string(ctx, -2, "meta");
// stack: js
Expand Down Expand Up @@ -571,7 +571,7 @@ void Script::cdsObject2dukObject(const std::shared_ptr<CdsObject>& obj)
for (const auto& res : obj->getResources()) {
auto attributes = res->getAttributes();
for (const auto& [key, val] : attributes) {
setProperty(resCount == 0 ? key : (std::to_string(resCount) + "-" + key), val);
setProperty(resCount == 0 ? key : (fmt::to_string(resCount) + "-" + key), val);
}
resCount++;
}
Expand Down
14 changes: 7 additions & 7 deletions src/database/mysql/mysql_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class MySQLDatabase : public SQLDatabase, public std::enable_shared_from_this<SQ

std::string quote(std::string value) const override;
std::string quote(const char* str) const override { return quote(std::string(str)); }
std::string quote(int val) const override { return std::to_string(val); }
std::string quote(unsigned int val) const override { return std::to_string(val); }
std::string quote(long val) const override { return std::to_string(val); }
std::string quote(unsigned long val) const override { return std::to_string(val); }
std::string quote(bool val) const override { return std::to_string(val ? '1' : '0'); }
std::string quote(char val) const override { return quote(std::to_string(val)); }
std::string quote(long long val) const override { return std::to_string(val); }
std::string quote(int val) const override { return fmt::to_string(val); }
std::string quote(unsigned int val) const override { return fmt::to_string(val); }
std::string quote(long val) const override { return fmt::to_string(val); }
std::string quote(unsigned long val) const override { return fmt::to_string(val); }
std::string quote(bool val) const override { return fmt::to_string(val ? '1' : '0'); }
std::string quote(char val) const override { return quote(fmt::to_string(val)); }
std::string quote(long long val) const override { return fmt::to_string(val); }
std::shared_ptr<SQLResult> select(const char* query, int length) override;
int exec(const char* query, int length, bool getLastInsertId = false) override;
void storeInternalSetting(const std::string& key, const std::string& value) override;
Expand Down
Loading

0 comments on commit 7c59528

Please sign in to comment.