diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2018-07-25 14:24:21 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@oath.com> | 2018-07-25 14:24:21 +0000 |
commit | 12c8f3005e202b31a8e0ff3816ce9d714a269046 (patch) | |
tree | a5d9ba0eedc49df2cea2dbdfea677c4c37ed3775 /searchcommon | |
parent | e3af3d215feb1e416b27b92bbf421dde281f3a09 (diff) |
Remove stringref::c_str()
The expected semantics of c_str() (a null-terminated string) cannot
be satisfied with a string reference, so remove the function entirely
to prevent people from using it in buggy ways.
Replaces c_str() with data() in places where it is presumed safe,
otherwise constructs temporary string instances. Certain callsites
have been de-stringref'd in favor of regular strings, in particular
where C APIs have been transitively called. The vast majority of
these were called with string parameters anyway, so should not
cause much extra allocation.
Diffstat (limited to 'searchcommon')
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schema.cpp | 6 | ||||
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schema.h | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index eafe9c28c1b..6cd9d87fa77 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -22,7 +22,7 @@ writeFields(vespalib::asciistream & os, { os << prefix << "[" << fields.size() << "]\n"; for (size_t i = 0; i < fields.size(); ++i) { - fields[i].write(os, vespalib::make_string("%s[%zu].", prefix.c_str(), i)); + fields[i].write(os, vespalib::make_string("%s[%zu].", prefix.data(), i)); } } @@ -245,7 +245,7 @@ Schema & Schema::operator=(Schema && rhs) = default; Schema::~Schema() { } bool -Schema::loadFromFile(const vespalib::stringref & fileName) +Schema::loadFromFile(const vespalib::string & fileName) { std::ifstream file(fileName.c_str()); if (!file) { @@ -284,7 +284,7 @@ Schema::loadFromFile(const vespalib::stringref & fileName) } bool -Schema::saveToFile(const vespalib::stringref & fileName) const +Schema::saveToFile(const vespalib::string & fileName) const { vespalib::asciistream os; writeToStream(os, true); diff --git a/searchcommon/src/vespa/searchcommon/common/schema.h b/searchcommon/src/vespa/searchcommon/common/schema.h index 374ea840f5c..1c3ab3ccd56 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.h +++ b/searchcommon/src/vespa/searchcommon/common/schema.h @@ -179,7 +179,7 @@ public: * @return true if the schema could be loaded. **/ bool - loadFromFile(const vespalib::stringref & fileName); + loadFromFile(const vespalib::string & fileName); /** * Save this schema to the file with the given name. @@ -188,7 +188,7 @@ public: * @return true if the schema could be saved. **/ bool - saveToFile(const vespalib::stringref & fileName) const; + saveToFile(const vespalib::string & fileName) const; vespalib::string toString() const; |