Reduce amount of copies for HashedString for improved performance
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <deukhoofd@gmail.com>
This commit is contained in:
2019-06-25 15:18:36 +02:00
parent bace7b294d
commit 48224afe45
13 changed files with 62 additions and 57 deletions

View File

@@ -349,7 +349,7 @@ TEST_CASE( "Lex identifier", "[lexer]" ) {
REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::Identifier);
REQUIRE(((IdentifierToken*)firstToken) -> GetValue() == HashedString("foo"));
REQUIRE(((IdentifierToken*)firstToken) -> GetValue() == HashedString::CreateLookup(u"foo"));
for (auto t: tokens){
delete t;
}

View File

@@ -203,7 +203,7 @@ TEST_CASE( "Parse String Tokens", "[parser]" ) {
TEST_CASE( "Parse Global Assignment", "[parser]" ) {
vector<const IToken*> v {
new IdentifierToken(HashedString("foo"),0,0),
new IdentifierToken(HashedString::CreateLookup(u"foo"),0,0),
new SimpleToken(TokenKind::AssignmentToken,0,0),
new SimpleToken(TokenKind::TrueKeyword,0,0),
new SimpleToken(TokenKind::EndOfFile,0,0)
@@ -216,7 +216,7 @@ TEST_CASE( "Parse Global Assignment", "[parser]" ) {
REQUIRE(firstStatement -> GetKind() == ParsedStatementKind::Assignment);
auto assignment = (ParsedAssignmentStatement*)firstStatement;
REQUIRE(!assignment -> IsLocal());
REQUIRE(assignment->GetIdentifier().GetHash() == HashedString("foo").GetHash());
REQUIRE(assignment->GetIdentifier().GetHash() == HashedString::CreateLookup(u"foo").GetHash());
REQUIRE(((LiteralBoolExpression*)assignment->GetExpression()) -> GetValue());
for (auto t : v){
@@ -228,7 +228,7 @@ TEST_CASE( "Parse Global Assignment", "[parser]" ) {
TEST_CASE( "Parse local Assignment", "[parser]" ) {
vector<const IToken*> v {
new SimpleToken(TokenKind::LocalKeyword,0,0),
new IdentifierToken(HashedString("foo"),0,0),
new IdentifierToken(HashedString(new u16string(u"foo")),0,0),
new SimpleToken(TokenKind::AssignmentToken,0,0),
new SimpleToken(TokenKind::TrueKeyword,0,0),
new SimpleToken(TokenKind::EndOfFile,0,0)
@@ -241,7 +241,7 @@ TEST_CASE( "Parse local Assignment", "[parser]" ) {
REQUIRE(firstStatement -> GetKind() == ParsedStatementKind::Assignment);
auto assignment = (ParsedAssignmentStatement*)firstStatement;
REQUIRE(assignment -> IsLocal());
REQUIRE(assignment->GetIdentifier().GetHash() == HashedString("foo").GetHash());
REQUIRE(assignment->GetIdentifier().GetHash() == HashedString::CreateLookup(u"foo").GetHash());
REQUIRE(((LiteralBoolExpression*)assignment->GetExpression()) -> GetValue());
for (auto t : v){
@@ -254,17 +254,17 @@ TEST_CASE( "Parse local Assignment", "[parser]" ) {
TEST_CASE( "Parse function declaration", "[parser]" ){
vector<const IToken*> v {
new SimpleToken(TokenKind::FunctionKeyword,0,0),
new IdentifierToken(HashedString("foo"),0,0),
new IdentifierToken(HashedString(new u16string(u"foo")),0,0),
new SimpleToken(TokenKind::OpenParenthesis,0,0),
new IdentifierToken(HashedString("number"),0,0),
new IdentifierToken(HashedString("bar"),0,0),
new IdentifierToken(HashedString(new u16string(u"number")),0,0),
new IdentifierToken(HashedString(new u16string(u"bar")),0,0),
new SimpleToken(TokenKind::CommaToken,0,0),
new IdentifierToken(HashedString("number"),0,0),
new IdentifierToken(HashedString("par"),0,0),
new IdentifierToken(HashedString(new u16string(u"number")),0,0),
new IdentifierToken(HashedString(new u16string(u"par")),0,0),
new SimpleToken(TokenKind::CloseParenthesis,0,0),
new IdentifierToken(HashedString("bar"),0,0),
new IdentifierToken(HashedString(new u16string(u"bar")),0,0),
new SimpleToken(TokenKind::PlusToken,0,0),
new IdentifierToken(HashedString("par"),0,0),
new IdentifierToken(HashedString(new u16string(u"par")),0,0),
new SimpleToken(TokenKind::EndKeyword,0,0),
new SimpleToken(TokenKind::EndOfFile,0,0),
};
@@ -275,12 +275,12 @@ TEST_CASE( "Parse function declaration", "[parser]" ){
auto firstStatement = parsedStatements -> at(0);
REQUIRE(firstStatement -> GetKind() == ParsedStatementKind::FunctionDeclaration);
auto functionDeclaration = (ParsedFunctionDeclarationStatement*)firstStatement;
REQUIRE(functionDeclaration->GetIdentifier() == HashedString("foo"));
REQUIRE(functionDeclaration->GetIdentifier() == HashedString::CreateLookup(u"foo"));
auto parameters = functionDeclaration->GetParameters();
CHECK(parameters -> at(0) ->GetType() == HashedString("number"));
CHECK(parameters -> at(0) ->GetIdentifier() == HashedString("bar"));
CHECK(parameters -> at(1) ->GetType() == HashedString("number"));
CHECK(parameters -> at(1) ->GetIdentifier() == HashedString("par"));
CHECK(parameters -> at(0) ->GetType() == HashedString::CreateLookup(u"number"));
CHECK(parameters -> at(0) ->GetIdentifier() == HashedString::CreateLookup(u"bar"));
CHECK(parameters -> at(1) ->GetType() == HashedString::CreateLookup(u"number"));
CHECK(parameters -> at(1) ->GetIdentifier() == HashedString::CreateLookup(u"par"));
for (auto t : v){
delete t;