Skip to content

Commit

Permalink
Improve: strip sstream which is extremely heavy & update dependencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 authored Jan 31, 2022
1 parent fdaf610 commit cb77683
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
classpath("com.android.tools.build:gradle:7.1.0")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ java {

dependencies {
compileOnly(gradleApi())
compileOnly("com.android.tools.build:gradle:7.0.0")
compileOnly("com.android.tools.build:gradle:7.1.0")
}

sourceSets {
Expand Down
5 changes: 3 additions & 2 deletions runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

android {
compileSdk = 31
ndkVersion = "23.0.7599858"
ndkVersion = "23.1.7779620"

defaultConfig {
minSdk = 26
Expand Down Expand Up @@ -45,6 +45,7 @@ android {
externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
version = "3.18.1"
}
}
buildFeatures {
Expand Down Expand Up @@ -77,4 +78,4 @@ afterEvaluate {
}
}
}
}
}
42 changes: 18 additions & 24 deletions runtime/src/main/cpp/properties.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
#include "properties.h"

#include <utility>
#include <sstream>

static std::string strip(const std::string &input) {
auto start_it = input.begin();
auto end_it = input.rbegin();
while (std::isspace(*start_it))
++start_it;
while (std::isspace(*end_it))
++end_it;
static std::string strip(const std::string_view &input) {
auto start_it = std::find_if_not(input.begin(), input.end(), std::isspace);
auto end_it = std::find_if_not(input.rbegin(), input.rend(), std::isspace);
return std::string(start_it, end_it.base());
}

Properties::Properties(std::unordered_map<std::string, std::string> const &properties) {
this->properties = properties;
Properties::Properties(std::unordered_map<std::string, std::string> properties) :
properties(std::move(properties)) {
}

std::string Properties::get(const std::string &key) const {
auto value = properties.find(key);
if (value == properties.end()) {
if (auto value = properties.find(key); value == properties.end()) {
return "";
} else {
return value->second;
}
return value->second;
}

Properties *Properties::load(Chunk *chunk) {
std::string text = std::string(static_cast<char *>(chunk->getData()), chunk->getLength());
std::istringstream ss{text};
std::string_view text{static_cast<char *>(chunk->getData()),
static_cast<size_t>(chunk->getLength())};

std::unordered_map<std::string, std::string> properties;
std::string line;

while (std::getline(ss, line)) {
size_t split = line.find('=');
if (split == std::string::npos) {
continue;
for (size_t start = 0, end; start != std::string::npos; start = end) {
end = text.find_first_of('\n', start + 1);
if (end != std::string::npos) {
auto line = text.substr(start, end);
if (size_t split = line.find('='); split != std::string::npos) {
properties[strip(line.substr(0, split))] = strip(line.substr(split + 1));
}
}

properties[strip(line.substr(0, split))] = strip(line.substr(split + 1));
}

return new Properties(properties);
return new Properties(std::move(properties));
}
2 changes: 1 addition & 1 deletion runtime/src/main/cpp/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Properties {
private:
Properties(std::unordered_map<std::string, std::string> const &properties);
Properties(std::unordered_map<std::string, std::string> properties);

public:
std::string get(std::string const &key) const;
Expand Down

0 comments on commit cb77683

Please sign in to comment.