mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-11 07:03:33 +02:00
Path: Use string_view more to avoid allocations
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include "Common/File/AndroidContentURI.h"
|
||||
|
||||
bool AndroidContentURI::Parse(const std::string &path) {
|
||||
bool AndroidContentURI::Parse(std::string_view path) {
|
||||
const char *prefix = "content://";
|
||||
if (!startsWith(path, prefix)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string components = path.substr(strlen(prefix));
|
||||
std::string_view components = path.substr(strlen(prefix));
|
||||
|
||||
std::vector<std::string> parts;
|
||||
SplitString(components, '/', parts);
|
||||
@@ -60,7 +60,7 @@ AndroidContentURI AndroidContentURI::WithRootFilePath(const std::string &filePat
|
||||
return uri;
|
||||
}
|
||||
|
||||
AndroidContentURI AndroidContentURI::WithComponent(const std::string &filePath) {
|
||||
AndroidContentURI AndroidContentURI::WithComponent(std::string_view filePath) {
|
||||
AndroidContentURI uri = *this;
|
||||
if (uri.file.empty()) {
|
||||
// Not sure what to do.
|
||||
@@ -68,16 +68,17 @@ AndroidContentURI AndroidContentURI::WithComponent(const std::string &filePath)
|
||||
}
|
||||
if (uri.file.back() == ':') {
|
||||
// Special case handling for Document URIs: Treat the ':' as a directory separator too (but preserved in the filename).
|
||||
uri.file = uri.file + filePath;
|
||||
uri.file.append(filePath);
|
||||
} else {
|
||||
uri.file = uri.file + "/" + filePath;
|
||||
uri.file.push_back('/');
|
||||
uri.file.append(filePath);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
AndroidContentURI AndroidContentURI::WithExtraExtension(const std::string &extension) {
|
||||
AndroidContentURI AndroidContentURI::WithExtraExtension(std::string_view extension) {
|
||||
AndroidContentURI uri = *this;
|
||||
uri.file = uri.file + extension;
|
||||
uri.file.append(extension);
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user