Skip to content

Commit

Permalink
tracy, cleanup into definition/declaration, some perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed May 31, 2022
1 parent cf2b59d commit c2ee83e
Show file tree
Hide file tree
Showing 25 changed files with 2,004 additions and 1,677 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/tracy"]
path = libs/tracy
url = [email protected]:wolfpld/tracy.git
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ project(typescript)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_CXX_FLAGS "-Wall -Wextra -O2")
# enable for profiling
#add_definitions(-DTRACY_ENABLE)

include_directories(libs/tracy/)

list(APPEND CMAKE_MODULE_PATH libs/)

#add_definitions(-DTRACY_ENABLE)
#include_directories(libs/tracy/)

add_subdirectory(libs/tracy)

link_libraries(Tracy::TracyClient)
add_subdirectory(src)

include_directories(libs)
Expand Down
1 change: 1 addition & 0 deletions libs/tracy
Submodule tracy added at a53c8b
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ add_definitions(-DTRACY_ENABLE)

add_subdirectory(tests)

set(CMAKE_CXX_FLAGS "-Wall -Wextra -O2")
#set(CMAKE_CXX_FLAGS "-Wall -Wextra -O3 -ffast-math")

add_library(typescript utf.h utf.cpp core.h core.cpp utilities.h utilities.cpp node_test.h node_test.cpp
syntax_cursor.h syntax_cursor.cpp parser2.h parser2.cpp types.h types.cpp path.h path.cpp
factory.h factory.cpp parenthesizer.h parenthesizer.cpp scanner.h scanner.cpp)
factory.h factory.cpp parenthesizer.h parenthesizer.cpp scanner.h scanner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../libs/tracy/TracyClient.cpp
)
27 changes: 21 additions & 6 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,30 @@ namespace ts::Debug {
}

namespace ts {
string substr(const string &str, int start, int length) {
string substr(const string &str, int start, optional<int> len) {
if (start <= 0 && len && len < 0) return "";
if (!len || *len < 0 || len > str.size()) *len = str.size();
if (start < 0) start += str.length();
if (length < 0) length = str.length() + length - start;
if (length < 0) return "";
return str.substr(start, length);
return str.substr(start, *len);
}
string substr(const string &str, int start) {
return substr(str, start, str.length());

//compatible with JavaScript's String.substring
string substring(const string &str, int start, optional<int> end) {
if (start < 0) start = 0;
int len = str.size();
if (end) {
if (*end < start) {
len = start - *end;
start = *end;
} else {
len = *end - start;
}
}
if (len < 0) len = 0;
if (start > str.size()) start = str.size();
return str.substr(start, len);
}

string replaceLeading(const string &text, const string &from, const string &to) {
if (0 == text.find(from)) {
string str = text;
Expand Down
12 changes: 9 additions & 3 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ namespace ts {
return const_hash(s);
}

string substr(const string &str, int start, int length);
//compatible with JavaScript's String.substr
string substr(const string &str, int start, optional<int> len = {});

string substr(const string &str, int start);
//compatible with JavaScript's String.substring
string substring(const string &str, int start, optional<int> end = {});

/**
* shared_ptr has optional semantic already built-in, so we use it instead of std::optional<shared_ptr<>>,
Expand Down Expand Up @@ -157,6 +159,7 @@ namespace ts {
}
return false;
}

template<typename T>
inline bool some(optional<vector<T>> array) {
return array && !array->empty();
Expand Down Expand Up @@ -223,7 +226,10 @@ namespace ts {

template<typename K, typename T>
inline optional<T> set(unordered_map<K, T> &m, K key, T v) {
m[key] = v;
// m.insert_or_assign(key, v);
std::cout << "set map: " << key << ", " << v << "\n";
// m.insert({key, v});
// m[key] = v;
}

template<typename T, typename U>
Expand Down
Loading

0 comments on commit c2ee83e

Please sign in to comment.