// Returns true if we successfully set the namespace
bool setNamespaceIfNotSet(const char* ns) {
- std::ostringstream oss;
if (!getNamespace().has_value()) {
- oss << ns << "::" << name;
- name = oss.str();
+ const auto ns_len = strlen(ns);
+ const auto old_name_size = name.size();
+ name.resize(ns_len + 2 + old_name_size);
+ // Shift current value of name to the end of the new space.
+ name.replace(name.size() - old_name_size, old_name_size, name, 0, old_name_size);
+ name.replace(0, ns_len, ns, ns_len);
+ name[ns_len] = ':';
+ name[ns_len + 1] = ':';
return true;
} else {
return false;