Stop using dynamic_cast for Types.
We now have a set of template functions CastType<AtomicType>, etc., that in turn use a new typeId field in each Type instance, allowing them to be inlined and to be quite efficient. This improves front-end performance for a particular large program by 28%.
This commit is contained in:
6
sym.cpp
6
sym.cpp
@@ -136,7 +136,7 @@ SymbolTable::LookupVariable(const char *name) {
|
||||
|
||||
bool
|
||||
SymbolTable::AddFunction(Symbol *symbol) {
|
||||
const FunctionType *ft = dynamic_cast<const FunctionType *>(symbol->type);
|
||||
const FunctionType *ft = CastType<FunctionType>(symbol->type);
|
||||
Assert(ft != NULL);
|
||||
if (LookupFunction(symbol->name.c_str(), ft) != NULL)
|
||||
// A function of the same name and type has already been added to
|
||||
@@ -182,7 +182,7 @@ SymbolTable::LookupFunction(const char *name, const FunctionType *type) {
|
||||
bool
|
||||
SymbolTable::AddType(const char *name, const Type *type, SourcePos pos) {
|
||||
const Type *t = LookupType(name);
|
||||
if (t != NULL && dynamic_cast<const UndefinedStructType *>(t) == NULL) {
|
||||
if (t != NULL && CastType<UndefinedStructType>(t) == NULL) {
|
||||
// If we have a previous declaration of anything other than an
|
||||
// UndefinedStructType with this struct name, issue an error. If
|
||||
// we have an UndefinedStructType, then we'll fall through to the
|
||||
@@ -270,7 +270,7 @@ SymbolTable::closestTypeMatch(const char *str, bool structsVsEnums) const {
|
||||
for (iter = types.begin(); iter != types.end(); ++iter) {
|
||||
// Skip over either StructTypes or EnumTypes, depending on the
|
||||
// value of the structsVsEnums parameter
|
||||
bool isEnum = (dynamic_cast<const EnumType *>(iter->second) != NULL);
|
||||
bool isEnum = (CastType<EnumType>(iter->second) != NULL);
|
||||
if (isEnum && structsVsEnums)
|
||||
continue;
|
||||
else if (!isEnum && !structsVsEnums)
|
||||
|
||||
Reference in New Issue
Block a user