private void InsertCachedSpriteInformation(Rendering.CachedSpriteInformation cachedSpriteInformation) { int lastIndex = _cachedSpriteInformations.Length - 1; int index = 0; while (index <= lastIndex) { int tmpIndex = index + lastIndex >> 1; var foundCachedSpriteInformation = _cachedSpriteInformations.GetItemAt(tmpIndex); if (foundCachedSpriteInformation.SpriteId < cachedSpriteInformation.SpriteId) { index = tmpIndex + 1; } else if (foundCachedSpriteInformation.SpriteId > cachedSpriteInformation.SpriteId) { lastIndex = tmpIndex - 1; } else { return; } } _cachedSpriteInformations.AddItemAt(cachedSpriteInformation, index); }
private void InsertCachedSpriteInformation(Rendering.CachedSpriteInformation cachedSpriteInformation) { int l = 0, r = _cachedSprites.Length - 1; while (l <= r) { int i = l + (r - l) / 2; var other = _cachedSprites.GetItemAt(i); if (other.SpriteId < cachedSpriteInformation.SpriteId) { l = i + 1; } else if (other.SpriteId > cachedSpriteInformation.SpriteId) { r = i - 1; } else { return; } } _cachedSprites.AddItemAt(cachedSpriteInformation, l); }