// Requires hierarchy lock private static int ExpandMixinsNoLock(RubyClass superClass, List<RubyModule/*!*/>/*!*/ existing, int index, IList<RubyModule/*!*/>/*!*/ added, bool recursive) { foreach (RubyModule module in added) { Assert.NotNull(module); int newIndex = existing.IndexOf(module); if (newIndex >= 0) { // Module is already present in _mixins // Update the insertion point so that we retain ordering of dependencies // If we're still in the initial level of recursion, repeat for module's mixins index = newIndex + 1; if (recursive) { index = ExpandMixinsNoLock(superClass, existing, index, module._mixins, false); } } else { // Module is not yet present in _mixins // Recursively insert module dependencies at the insertion point, then insert module itself newIndex = ExpandMixinsNoLock(superClass, existing, index, module._mixins, false); // insert module only if it is not an ancestor of the superclass: if (superClass == null || !superClass.HasAncestorNoLock(module)) { existing.Insert(index, module); index = newIndex + 1; } else { index = newIndex; } } } return index; }