Skip to content

Commit

Permalink
Merge pull request #2247 from WalterBright/speed_up_search
Browse files Browse the repository at this point in the history
speed up based on gprof data
  • Loading branch information
andralex committed Jun 24, 2013
2 parents c946994 + 60862ed commit ed061d5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
66 changes: 23 additions & 43 deletions src/dsymbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,48 +849,44 @@ Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s)
return sd;
}

/*****************************************
* This function is #1 on the list of functions that eat cpu time.
* Be very, very careful about slowing it down.
*/

Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
{
//printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags);
//if (strcmp(ident->toChars(),"c") == 0) *(char*)0=0;

if (Package *pkg = isPackage())
{
if (!pkg->isModule() && pkg->mod)
{
// Prefer full package name.
Dsymbol *s = pkg->symtab ? pkg->symtab->lookup(ident) : NULL;
if (s)
return s;
//printf("[%s] through pkdmod: %s\n", loc.toChars(), pkg->toChars());
return pkg->mod->search(loc, ident, flags);
}
}

// Look in symbols declared in this module
Dsymbol *s = symtab ? symtab->lookup(ident) : NULL;
//printf("\ts = %p, imports = %p, %d\n", s, imports, imports ? imports->dim : 0);
if (s)
Dsymbol *s1 = symtab ? symtab->lookup(ident) : NULL;
//printf("\ts1 = %p, imports = %p, %d\n", s1, imports, imports ? imports->dim : 0);
if (s1)
{
//printf("\ts = '%s.%s'\n",toChars(),s->toChars());
//printf("\ts = '%s.%s'\n",toChars(),s1->toChars());
return s1;
}
else if (imports)
else if (!imports)
return NULL;
else
{
Dsymbol *s = NULL;
OverloadSet *a = NULL;

// Look in imported modules
for (size_t i = 0; i < imports->dim; i++)
{ Dsymbol *ss = (*imports)[i];
Dsymbol *s2;

{
// If private import, don't search it
if (flags & 1 && prots[i] == PROTprivate)
continue;

Dsymbol *ss = (*imports)[i];

//printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport());
/* Don't find private members if ss is a module
*/
s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0);
Dsymbol *s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0);
if (!s)
s = s2;
else if (s2 && s != s2)
Expand Down Expand Up @@ -972,30 +968,14 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)

if (s)
{
if (!(flags & 2))
{ Declaration *d = s->isDeclaration();
if (d && d->protection == PROTprivate &&
!d->parent->isTemplateMixin())
error(loc, "%s is private", d->toPrettyChars());

AggregateDeclaration *ad = s->isAggregateDeclaration();
if (ad && ad->protection == PROTprivate &&
!ad->parent->isTemplateMixin())
error(loc, "%s is private", ad->toPrettyChars());

EnumDeclaration *ed = s->isEnumDeclaration();
if (ed && ed->protection == PROTprivate &&
!ed->parent->isTemplateMixin())
error(loc, "%s is private", ed->toPrettyChars());

TemplateDeclaration *td = s->isTemplateDeclaration();
if (td && td->protection == PROTprivate &&
!td->parent->isTemplateMixin())
error(loc, "%s is private", td->toPrettyChars());
if (!(flags & 2) && s->prot() == PROTprivate && !s->parent->isTemplateMixin())
{
if (!s->isImport())
error(loc, "%s %s is private", s->kind(), s->toPrettyChars());
}
}
return s;
}
return s;
}

void ScopeDsymbol::importScope(Dsymbol *s, PROT protection)
Expand Down
5 changes: 5 additions & 0 deletions src/enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ bool EnumDeclaration::isDeprecated()
return isdeprecated;
}

PROT EnumDeclaration::prot()
{
return protection;
}

Dsymbol *EnumDeclaration::search(Loc loc, Identifier *ident, int flags)
{
//printf("%s.EnumDeclaration::search('%s')\n", toChars(), ident->toChars());
Expand Down
1 change: 1 addition & 0 deletions src/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class EnumDeclaration : public ScopeDsymbol
Dsymbol *search(Loc, Identifier *ident, int flags);
#endif
bool isDeprecated(); // is Dsymbol deprecated?
PROT prot();

void emitComment(Scope *sc);
void toJson(JsonOut *json);
Expand Down
14 changes: 14 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,20 @@ DsymbolTable *Package::resolve(Identifiers *packages, Dsymbol **pparent, Package
return dst;
}

Dsymbol *Package::search(Loc loc, Identifier *ident, int flags)
{
if (!isModule() && mod)
{
// Prefer full package name.
Dsymbol *s = symtab ? symtab->lookup(ident) : NULL;
if (s)
return s;
//printf("[%s] through pkdmod: %s\n", loc.toChars(), toChars());
return mod->search(loc, ident, flags);
}

return ScopeDsymbol::search(loc, ident, flags);
}

/* =========================== ===================== */

Expand Down
3 changes: 2 additions & 1 deletion src/module.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2012 by Digital Mars
// Copyright (c) 1999-2013 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -53,6 +53,7 @@ class Package : public ScopeDsymbol
Package *isPackage() { return this; }

virtual void semantic(Scope *) { }
Dsymbol *search(Loc loc, Identifier *ident, int flags);
};

class Module : public Package
Expand Down

0 comments on commit ed061d5

Please sign in to comment.