Updated Lexer::make_lexer to return a unique_ptr

This is part of my quest to replace all unneeded std::shared_ptrs for
std::unique_ptrs to improve performance, since there is no need for
reference counting for pointers that are uniquely used. I also had to
change the first parameter of Lexer::assign_parent_location to a
std::unique_ptr<Lexer>& so that it can accept the new result of
make_lexer.
This commit is contained in:
apio 2022-06-22 18:12:50 +02:00
parent 8d71d9c120
commit e4fd6c863a
2 changed files with 5 additions and 5 deletions

View File

@ -60,12 +60,12 @@ std::string Lexer::recalculate_current_line(const std::string& text)
return final_str;
}
std::shared_ptr<Lexer> Lexer::make_lexer(const std::string& fname)
std::unique_ptr<Lexer> Lexer::make_lexer(const std::string& fname)
{
return std::shared_ptr<Lexer>(new Lexer(fname)); // not using make_shared because the constructor is private
return std::unique_ptr<Lexer>(new Lexer(fname)); // not using make_shared because the constructor is private
}
void Lexer::assign_parent_location(std::shared_ptr<Lexer>& lexer, const std::shared_ptr<Location>& loc)
void Lexer::assign_parent_location(std::unique_ptr<Lexer>& lexer, const std::shared_ptr<Location>& loc)
{
lexer->loc.parent = loc;
}

View File

@ -46,8 +46,8 @@ class Lexer
TokenStream lex(const std::string& text);
/* Create a new Lexer and return a pointer to it. */
static std::shared_ptr<Lexer> make_lexer(const std::string& fname);
static std::unique_ptr<Lexer> make_lexer(const std::string& fname);
/* If the Lexer is lexing an impòrted file, give it the location in the parent file at which it was imported. */
static void assign_parent_location(std::shared_ptr<Lexer>& lexer, const std::shared_ptr<Location>& loc);
static void assign_parent_location(std::unique_ptr<Lexer>& lexer, const std::shared_ptr<Location>& loc);
};