Skip to content

Commit

Permalink
Remove String alias (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Jul 21, 2024
1 parent 4a52151 commit 1816371
Show file tree
Hide file tree
Showing 49 changed files with 507 additions and 449 deletions.
1 change: 1 addition & 0 deletions poac.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ filters = [
"-runtime/references", # non-const reference rather than a pointer
"-whitespace",
"+whitespace/ending_newline",
"-runtime/string", # FIXME: remove this after fixing all the warnings
]
19 changes: 10 additions & 9 deletions src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
#include <algorithm>
#include <cctype>
#include <memory>
#include <string>
#include <thread>
#include <utility>

String
std::string
toUpper(const StringRef str) noexcept {
String res;
std::string res;
for (const unsigned char c : str) {
res += static_cast<char>(std::toupper(c));
}
return res;
}

String
std::string
toMacroName(const StringRef name) noexcept {
String macroName;
std::string macroName;
for (const unsigned char c : name) {
if (std::isalpha(c)) {
macroName += static_cast<char>(std::toupper(c));
Expand All @@ -42,11 +43,11 @@ execCmd(const StringRef cmd) noexcept {
return exitCode;
}

static std::pair<String, int>
static std::pair<std::string, int>
getCmdOutputImpl(const StringRef cmd) {
constexpr usize bufferSize = 128;
std::array<char, bufferSize> buffer{};
String output;
std::string output;

FILE* pipe = popen(cmd.data(), "r");
if (!pipe) {
Expand All @@ -65,7 +66,7 @@ getCmdOutputImpl(const StringRef cmd) {
return { output, exitCode };
}

String
std::string
getCmdOutput(const StringRef cmd, const usize retry) {
logger::debug("Running `", cmd, '`');

Expand All @@ -87,7 +88,7 @@ getCmdOutput(const StringRef cmd, const usize retry) {

bool
commandExists(const StringRef cmd) noexcept {
String checkCmd = "command -v ";
std::string checkCmd = "command -v ";
checkCmd += cmd;
checkCmd += " >/dev/null 2>&1";
return execCmd(checkCmd) == EXIT_SUCCESS;
Expand Down Expand Up @@ -182,7 +183,7 @@ void
testLevDistance() {
// Test bytelength agnosticity
for (char c = 0; c < std::numeric_limits<char>::max(); ++c) {
const String str(1, c);
const std::string str(1, c);
assertEq(levDistance(str, str), 0UL);
}

Expand Down
22 changes: 12 additions & 10 deletions src/Algos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
#include <queue>
#include <span>
#include <sstream>
#include <string>
#include <utility>

String toUpper(StringRef str) noexcept;
String toMacroName(StringRef name) noexcept;
std::string toUpper(StringRef str) noexcept;
std::string toMacroName(StringRef name) noexcept;

int execCmd(StringRef cmd) noexcept;
String getCmdOutput(StringRef cmd, usize retry = 3);
std::string getCmdOutput(StringRef cmd, usize retry = 3);
bool commandExists(StringRef cmd) noexcept;

template <typename T>
Vec<String>
Vec<std::string>
topoSort(
const HashMap<String, T>& list, const HashMap<String, Vec<String>>& adjList
const HashMap<std::string, T>& list,
const HashMap<std::string, Vec<std::string>>& adjList
) {
HashMap<String, u32> inDegree;
HashMap<std::string, u32> inDegree;
for (const auto& var : list) {
inDegree[var.first] = 0;
}
Expand All @@ -40,24 +42,24 @@ topoSort(
}
}

std::queue<String> zeroInDegree;
std::queue<std::string> zeroInDegree;
for (const auto& var : inDegree) {
if (var.second == 0) {
zeroInDegree.push(var.first);
}
}

Vec<String> res;
Vec<std::string> res;
while (!zeroInDegree.empty()) {
const String node = zeroInDegree.front();
const std::string node = zeroInDegree.front();
zeroInDegree.pop();
res.push_back(node);

if (!adjList.contains(node)) {
// No dependencies
continue;
}
for (const String& neighbor : adjList.at(node)) {
for (const std::string& neighbor : adjList.at(node)) {
inDegree[neighbor]--;
if (inDegree[neighbor] == 0) {
zeroInDegree.push(neighbor);
Expand Down
Loading

0 comments on commit 1816371

Please sign in to comment.