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:
parent
8d71d9c120
commit
e4fd6c863a
@ -60,12 +60,12 @@ std::string Lexer::recalculate_current_line(const std::string& text)
|
|||||||
return final_str;
|
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;
|
lexer->loc.parent = loc;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ class Lexer
|
|||||||
TokenStream lex(const std::string& text);
|
TokenStream lex(const std::string& text);
|
||||||
|
|
||||||
/* Create a new Lexer and return a pointer to it. */
|
/* 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. */
|
/* 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);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user