summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2019-01-15 13:20:05 -0800
committerGitHub <noreply@github.com>2019-01-15 13:20:05 -0800
commitd24427dcc8cd6e0dbcd8c302eb2e8a5d0d6fdead (patch)
tree37575895001e5dd9509c5c42fd539253516e21fd /src/emscripten-optimizer
parent45714b5fc6cf14c112bc4f188aca427464ab69d8 (diff)
downloadbinaryen-d24427dcc8cd6e0dbcd8c302eb2e8a5d0d6fdead.tar.gz
binaryen-d24427dcc8cd6e0dbcd8c302eb2e8a5d0d6fdead.tar.bz2
binaryen-d24427dcc8cd6e0dbcd8c302eb2e8a5d0d6fdead.zip
Code style improvements (#1868)
* Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
Diffstat (limited to 'src/emscripten-optimizer')
-rw-r--r--src/emscripten-optimizer/istring.h6
-rw-r--r--src/emscripten-optimizer/optimizer.h4
-rw-r--r--src/emscripten-optimizer/parser.h6
-rw-r--r--src/emscripten-optimizer/simple_ast.cpp9
-rw-r--r--src/emscripten-optimizer/simple_ast.h21
5 files changed, 24 insertions, 22 deletions
diff --git a/src/emscripten-optimizer/istring.h b/src/emscripten-optimizer/istring.h
index 87da87473..5a7d05162 100644
--- a/src/emscripten-optimizer/istring.h
+++ b/src/emscripten-optimizer/istring.h
@@ -35,7 +35,7 @@
namespace cashew {
struct IString {
- const char *str;
+ const char *str = nullptr;
static size_t hash_c(const char *str) { // see http://www.cse.yorku.ca/~oz/hash.html
unsigned int hash = 5381;
@@ -59,7 +59,7 @@ struct IString {
}
};
- IString() : str(nullptr) {}
+ IString() = default;
IString(const char *s, bool reuse=true) { // if reuse=true, then input is assumed to remain alive; not copied
assert(s);
set(s, reuse);
@@ -178,7 +178,7 @@ namespace cashew {
class IStringSet : public std::unordered_set<IString> {
std::vector<char> data;
public:
- IStringSet() {}
+ IStringSet() = default;
IStringSet(const char *init) { // comma-delimited list
int size = strlen(init) + 1;
data.resize(size);
diff --git a/src/emscripten-optimizer/optimizer.h b/src/emscripten-optimizer/optimizer.h
index c3939abf4..12d7c1433 100644
--- a/src/emscripten-optimizer/optimizer.h
+++ b/src/emscripten-optimizer/optimizer.h
@@ -59,7 +59,7 @@ AsmType detectType(cashew::Ref node, AsmData *asmData=nullptr, bool inVarDef=fal
struct AsmData {
struct Local {
- Local() {}
+ Local() = default;
Local(AsmType type, bool param) : type(type), param(param) {}
AsmType type;
bool param; // false if a var
@@ -92,7 +92,7 @@ struct AsmData {
return isLocal(name) && !locals[name].param;
}
- AsmData() {} // if you want to fill in the data yourself
+ AsmData() = default; // if you want to fill in the data yourself
AsmData(cashew::Ref f); // if you want to read data from f, and modify it as you go (parallel to denormalize)
void denormalize();
diff --git a/src/emscripten-optimizer/parser.h b/src/emscripten-optimizer/parser.h
index ae3c6b067..78ed27933 100644
--- a/src/emscripten-optimizer/parser.h
+++ b/src/emscripten-optimizer/parser.h
@@ -910,8 +910,8 @@ class Parser {
// Debugging
- char *allSource;
- int allSize;
+ char *allSource = nullptr;
+ int allSize = 0;
static void dump(const char *where, char* curr) {
/*
@@ -938,7 +938,7 @@ class Parser {
public:
- Parser() : allSource(nullptr), allSize(0) {
+ Parser() {
expressionPartsStack.resize(1);
}
diff --git a/src/emscripten-optimizer/simple_ast.cpp b/src/emscripten-optimizer/simple_ast.cpp
index b3a3cae84..c9659f964 100644
--- a/src/emscripten-optimizer/simple_ast.cpp
+++ b/src/emscripten-optimizer/simple_ast.cpp
@@ -188,7 +188,7 @@ void dump(const char *str, Ref node, bool pretty) {
// Traversals
struct TraverseInfo {
- TraverseInfo() {}
+ TraverseInfo() = default;
TraverseInfo(Ref node, ArrayStorage* arr) : node(node), arr(arr), index(0) {}
Ref node;
ArrayStorage* arr;
@@ -199,10 +199,11 @@ template<class T, int init>
struct StackedStack { // a stack, on the stack
T stackStorage[init];
T* storage;
- int used, available; // used amount, available amount
- bool alloced;
+ int used = 0;
+ int available = init; // used amount, available amount
+ bool alloced = false;
- StackedStack() : used(0), available(init), alloced(false) {
+ StackedStack() {
storage = stackStorage;
}
~StackedStack() {
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index 9cbe7616c..de8122ba1 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -112,7 +112,7 @@ struct Value {
AssignName_ = 7
};
- Type type;
+ Type type = Null;
typedef std::unordered_map<IString, Ref> ObjectStorage;
@@ -131,14 +131,14 @@ struct Value {
};
// constructors all copy their input
- Value() : type(Null), num(0) {}
- explicit Value(const char *s) : type(Null) {
+ Value() {}
+ explicit Value(const char *s) {
setString(s);
}
- explicit Value(double n) : type(Null) {
+ explicit Value(double n) {
setNumber(n);
}
- explicit Value(ArrayStorage &a) : type(Null) {
+ explicit Value(ArrayStorage &a) {
setArray();
*arr = a;
}
@@ -544,15 +544,16 @@ void traverseFunctions(Ref ast, std::function<void (Ref)> visit);
struct JSPrinter {
bool pretty, finalize;
- char *buffer;
- size_t size, used;
+ char *buffer = nullptr;
+ size_t size = 0;
+ size_t used = 0;
- int indent;
- bool possibleSpace; // add a space to separate identifiers
+ int indent = 0;
+ bool possibleSpace = false; // add a space to separate identifiers
Ref ast;
- JSPrinter(bool pretty_, bool finalize_, Ref ast_) : pretty(pretty_), finalize(finalize_), buffer(0), size(0), used(0), indent(0), possibleSpace(false), ast(ast_) {}
+ JSPrinter(bool pretty_, bool finalize_, Ref ast_) : pretty(pretty_), finalize(finalize_), ast(ast_) {}
~JSPrinter() {
free(buffer);