summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/programs/program_parameters.cpp30
-rw-r--r--src/mbgl/shaders/shaders.cpp15
-rw-r--r--src/mbgl/util/url.cpp20
3 files changed, 35 insertions, 30 deletions
diff --git a/src/mbgl/programs/program_parameters.cpp b/src/mbgl/programs/program_parameters.cpp
index e76ec4be71..2c70062e08 100644
--- a/src/mbgl/programs/program_parameters.cpp
+++ b/src/mbgl/programs/program_parameters.cpp
@@ -1,7 +1,5 @@
#include <mbgl/programs/program_parameters.hpp>
-
-#include <iomanip>
-#include <sstream>
+#include <mbgl/util/string.hpp>
namespace mbgl {
@@ -9,14 +7,15 @@ ProgramParameters::ProgramParameters(const float pixelRatio,
const bool overdraw,
optional<std::string> cacheDir_)
: defines([&] {
- std::ostringstream ss;
- ss.imbue(std::locale("C"));
- ss.setf(std::ios_base::showpoint);
- ss << "#define DEVICE_PIXEL_RATIO " << pixelRatio << std::endl;
+ std::string result;
+ result.reserve(32);
+ result += "#define DEVICE_PIXEL_RATIO ";
+ result += util::toString(pixelRatio, true);
+ result += "\n";
if (overdraw) {
- ss << "#define OVERDRAW_INSPECTOR" << std::endl;
+ result += "#define OVERDRAW_INSPECTOR\n";
}
- return ss.str();
+ return result;
}()),
cacheDir(std::move(cacheDir_)) {
}
@@ -29,10 +28,15 @@ optional<std::string> ProgramParameters::cachePath(const char* name) const {
if (!cacheDir) {
return {};
} else {
- std::ostringstream ss;
- ss << *cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0')
- << std::setw(sizeof(size_t) * 2) << std::hex << std::hash<std::string>()(defines) << ".pbf";
- return ss.str();
+ std::string result;
+ result.reserve(cacheDir->length() + 64);
+ result += *cacheDir;
+ result += "/com.mapbox.gl.shader.";
+ result += name;
+ result += ".";
+ result += util::toHex(std::hash<std::string>()(defines));
+ result += ".pbf";
+ return result;
}
}
diff --git a/src/mbgl/shaders/shaders.cpp b/src/mbgl/shaders/shaders.cpp
index 2e5a318024..04cfda35cc 100644
--- a/src/mbgl/shaders/shaders.cpp
+++ b/src/mbgl/shaders/shaders.cpp
@@ -1,10 +1,9 @@
#include <mbgl/shaders/shaders.hpp>
#include <mbgl/shaders/preludes.hpp>
#include <mbgl/programs/program_parameters.hpp>
+#include <mbgl/util/string.hpp>
#include <cassert>
-#include <sstream>
-#include <iomanip>
namespace mbgl {
namespace shaders {
@@ -18,12 +17,12 @@ std::string vertexSource(const ProgramParameters& parameters, const char* vertex
}
std::string programIdentifier(const std::string& vertexSource, const std::string& fragmentSource) {
- std::ostringstream ss;
- ss << std::setfill('0') << std::setw(sizeof(size_t) * 2) << std::hex;
- ss << std::hash<std::string>()(vertexSource);
- ss << std::hash<std::string>()(fragmentSource);
- ss << "v2";
- return ss.str();
+ std::string result;
+ result.reserve(sizeof(size_t) * 2 * 2 + 2 + 1);
+ result += util::toHex(std::hash<std::string>()(vertexSource));
+ result += util::toHex(std::hash<std::string>()(fragmentSource));
+ result += "v2";
+ return result;
}
} // namespace shaders
diff --git a/src/mbgl/util/url.cpp b/src/mbgl/util/url.cpp
index a4263502ef..37a70007ca 100644
--- a/src/mbgl/util/url.cpp
+++ b/src/mbgl/util/url.cpp
@@ -1,8 +1,6 @@
#include <mbgl/util/url.hpp>
#include <mbgl/util/token.hpp>
-#include <iomanip>
-#include <sstream>
#include <string>
#include <cstdlib>
#include <algorithm>
@@ -24,26 +22,30 @@ inline bool isSchemeCharacter(char c) {
return isAlphaNumericCharacter(c) || c == '-' || c == '+' || c == '.';
}
+inline char toLowerHex(char c) {
+ c &= 0x0F;
+ return '0' + c + (c > 9 ? 7 : 0);
+}
+
} // namespace
namespace mbgl {
namespace util {
std::string percentEncode(const std::string& input) {
- std::ostringstream encoded;
-
- encoded.fill('0');
- encoded << std::hex;
+ std::string encoded;
for (auto c : input) {
if (isAlphaNumericCharacter(c) || c == '-' || c == '_' || c == '.' || c == '~') {
- encoded << c;
+ encoded += c;
} else {
- encoded << '%' << std::setw(2) << int(c);
+ encoded += '%';
+ encoded += toLowerHex(c >> 4);
+ encoded += toLowerHex(c);
}
}
- return encoded.str();
+ return encoded;
}
std::string percentDecode(const std::string& input) {