@@ -108,15 +108,18 @@ trait Scopes {
108108 *
109109 * @param e ...
110110 */
111- def enter (e : ScopeEntry ) {
111+ protected def enter (e : ScopeEntry ) {
112112 elemsCache = null
113- if (hashtable ne null ) {
114- val i = e.sym.name.start & HASHMASK
115- elems.tail = hashtable(i)
116- hashtable(i) = elems
117- } else if (size >= MIN_HASH ) {
113+ if (hashtable ne null )
114+ enterInHash(e)
115+ else if (size >= MIN_HASH )
118116 createHash()
119- }
117+ }
118+
119+ private def enterInHash (e : ScopeEntry ): Unit = {
120+ val i = e.sym.name.start & HASHMASK
121+ e.tail = hashtable(i)
122+ hashtable(i) = e
120123 }
121124
122125 /** enter a symbol
@@ -136,15 +139,23 @@ trait Scopes {
136139
137140 private def createHash () {
138141 hashtable = new Array [ScopeEntry ](HASHSIZE )
139- enterInHash (elems)
142+ enterAllInHash (elems)
140143 }
141144
142- private def enterInHash (e : ScopeEntry ) {
145+ private def enterAllInHash (e : ScopeEntry , n : Int = 0 ) {
143146 if (e ne null ) {
144- enterInHash(e.next)
145- val i = e.sym.name.start & HASHMASK
146- e.tail = hashtable(i)
147- hashtable(i) = e
147+ if (n < maxRecursions) {
148+ enterAllInHash(e.next, n + 1 )
149+ enterInHash(e)
150+ } else {
151+ var entries : List [ScopeEntry ] = List ()
152+ var ee = e
153+ while (ee ne null ) {
154+ entries = ee :: entries
155+ ee = ee.next
156+ }
157+ entries foreach enterInHash
158+ }
148159 }
149160 }
150161
@@ -332,5 +343,8 @@ trait Scopes {
332343 /** The error scope.
333344 */
334345 class ErrorScope (owner : Symbol ) extends Scope (null : ScopeEntry )
346+
347+ private final val maxRecursions = 1000
348+
335349}
336350
0 commit comments