Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comment optimization. #249

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions src/CatLib.Core/CatLib/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using CatLib.EventDispatcher;
using CatLib.Support;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
Expand All @@ -27,44 +26,13 @@ namespace CatLib
/// </summary>
public class Application : CatLibContainer, IApplication
{
/// <summary>
/// The version of the framework application.
/// </summary>
private static string version;

/// <summary>
/// The types of the loaded service providers.
/// </summary>
private readonly List<IServiceProvider> loadedProviders;

/// <summary>
/// The main thread id.
/// </summary>
private readonly int mainThreadId;

/// <summary>
/// True if the application has been bootstrapped.
/// </summary>
private bool bootstrapped;

/// <summary>
/// True if the application has been initialized.
/// </summary>
private bool inited;

/// <summary>
/// True if the <see cref="Register"/> is being executed.
/// </summary>
private bool registering;

/// <summary>
/// The unique runtime id.
/// </summary>
private long incrementId;

/// <summary>
/// The debug level.
/// </summary>
private DebugLevel debugLevel;
private IEventDispatcher dispatcher;

Expand Down Expand Up @@ -359,31 +327,6 @@ public long GetRuntimeId()
return Interlocked.Increment(ref incrementId);
}

/// <summary>
/// Call the iterator with the default coroutine.
/// </summary>
/// <param name="iterator">The iterator.</param>
protected static void StartCoroutine(IEnumerator iterator)
{
var stack = new Stack<IEnumerator>();
stack.Push(iterator);
do
{
iterator = stack.Pop();
while (iterator.MoveNext())
{
if (!(iterator.Current is IEnumerator nextCoroutine))
{
continue;
}

stack.Push(iterator);
iterator = nextCoroutine;
}
}
while (stack.Count > 0);
}

/// <summary>
/// Initialize the specified service provider.
/// </summary>
Expand All @@ -406,9 +349,6 @@ protected override void GuardConstruct(string method)
base.GuardConstruct(method);
}

/// <summary>
/// Register the core service aliases.
/// </summary>
private void RegisterBaseBindings()
{
this.Singleton<IApplication>(() => this).Alias<Application>().Alias<IContainer>();
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/CatLib/DebugLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace CatLib
{
/// <summary>
/// Framework debug level.
/// Indicates the framework debug level.
/// </summary>
public enum DebugLevel
{
Expand Down
19 changes: 0 additions & 19 deletions src/CatLib.Core/CatLib/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,10 @@ namespace CatLib
/// </remarks>
public abstract class Facade<TService>
{
/// <summary>
/// The service name.
/// </summary>
private static readonly string Service;

/// <summary>
/// The resolved object instance.
/// </summary>
private static TService instance;

/// <summary>
/// The resolved object bind data.
/// </summary>
private static IBindData binder;

/// <summary>
/// Whether the facade has been initialized.
/// </summary>
private static bool inited;

/// <summary>
/// Whether the resolved object has been released.
/// </summary>
private static bool released;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/CatLib.Core/CatLib/ServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Document: https://catlib.io/
*/

using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace CatLib
Expand Down
22 changes: 2 additions & 20 deletions src/CatLib.Core/Container/BindData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class BindData : Bindable<IBindData>, IBindData
/// <param name="service">The service name.</param>
/// <param name="concrete">The service concrete.</param>
/// <param name="isStatic">Whether the service is singleton(static).</param>
public BindData(Container container, string service, Func<IContainer, object[], object> concrete, bool isStatic)
public BindData(CatLibContainer container, string service, Func<IContainer, object[], object> concrete, bool isStatic)
: base(container, service)
{
Concrete = concrete;
Expand Down Expand Up @@ -105,29 +105,16 @@ public IBindData OnRelease(Action<IBindData, object> closure)
return this;
}

/// <summary>
/// Trigger all of the local resolving callbacks.
/// </summary>
/// <param name="instance">The service instance.</param>
/// <returns>The decorated service instance.</returns>
internal object TriggerResolving(object instance)
{
return CatLibContainer.Trigger(this, instance, resolving);
}

/// <inheritdoc cref="TriggerResolving"/>
/// <summary>
/// Trigger all of the local after resolving callbacks.
/// </summary>
internal object TriggerAfterResolving(object instance)
{
return CatLibContainer.Trigger(this, instance, afterResolving);
}

/// <inheritdoc cref="TriggerResolving"/>
/// <summary>
/// Trigger all of the local release callbacks.
/// </summary>
internal object TriggerRelease(object instance)
{
return CatLibContainer.Trigger(this, instance, release);
Expand All @@ -136,14 +123,9 @@ internal object TriggerRelease(object instance)
/// <inheritdoc />
protected override void ReleaseBind()
{
((Container)Container).Unbind(this);
((CatLibContainer)Container).Unbind(this);
}

/// <summary>
/// Register a new callback in specified list.
/// </summary>
/// <param name="closure">The callback.</param>
/// <param name="list">The specified list.</param>
private void AddClosure(Action<IBindData, object> closure, ref List<Action<IBindData, object>> list)
{
Guard.NotNull(closure, nameof(closure));
Expand Down
26 changes: 4 additions & 22 deletions src/CatLib.Core/Container/Bindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,9 @@ namespace CatLib.Container
/// </summary>
public abstract class Bindable : IBindable
{
/// <summary>
/// Synchronize locking object.
/// </summary>
private readonly object locker = new object();

/// <inheritdoc cref="Container"/>
private readonly Container container;

/// <summary>
/// The mapping of the service context.
/// </summary>
private Dictionary<string, string> contextual;

/// <summary>
/// The closure mapping of the service context.
/// </summary>
private Dictionary<string, Func<object>> contextualClosure;

/// <summary>
/// Whether the bindable data is destroyed.
/// </summary>
private bool isDestroy;

/// <summary>
Expand All @@ -66,12 +48,12 @@ protected Bindable(Container container, string service)
/// <summary>
/// Gets synchronize locking object.
/// </summary>
protected object Locker => locker;
protected object Locker { get; } = new object();

/// <inheritdoc />
public void Unbind()
{
lock (locker)
lock (Locker)
{
isDestroy = true;
ReleaseBind();
Expand All @@ -85,7 +67,7 @@ public void Unbind()
/// <param name="given">Given speified service or alias.</param>
internal void AddContextual(string needs, string given)
{
lock (locker)
lock (Locker)
{
AssertDestroyed();
if (contextual == null)
Expand All @@ -107,7 +89,7 @@ internal void AddContextual(string needs, string given)
/// <param name="given">The closure return the given service instance.</param>
internal void AddContextual(string needs, Func<object> given)
{
lock (locker)
lock (Locker)
{
AssertDestroyed();
if (contextualClosure == null)
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/Container/ExtendBindData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace CatLib.Container
{
/// <summary>
/// 绑定数据拓展.
/// An extension function for <see cref="BindData"/>.
/// </summary>
public static class ExtendBindData
{
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/Container/ExtendContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace CatLib.Container
{
/// <summary>
/// The container extension function.
/// An extension function for <see cref="Container"/>.
/// </summary>
public static class ExtendContainer
{
Expand Down
9 changes: 0 additions & 9 deletions src/CatLib.Core/Container/GivenData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@ namespace CatLib.Container
internal sealed class GivenData<TReturn> : IGivenData<TReturn>
where TReturn : class, IBindable<TReturn>
{
/// <inheritdoc cref="BindData"/>
private readonly Bindable<TReturn> bindable;

/// <summary>
/// The container to which the service belongs.
/// </summary>
private readonly Container container;

/// <summary>
/// The demand service.
/// </summary>
private string needs;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/Container/IParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace CatLib.Container
public interface IParams
{
/// <summary>
/// Get a parameter.
/// Get parameters by name.
/// </summary>
/// <param name="key">The parameter name.</param>
/// <param name="value">The parameter value.</param>
Expand Down
3 changes: 0 additions & 3 deletions src/CatLib.Core/Container/MethodBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ namespace CatLib.Container
/// </summary>
internal sealed class MethodBind : Bindable<IMethodBind>, IMethodBind
{
/// <summary>
/// The <see cref="MethodContainer"/> instance.
/// </summary>
private readonly MethodContainer methodContainer;

/// <summary>
Expand Down
21 changes: 1 addition & 20 deletions src/CatLib.Core/Container/MethodContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,9 @@ namespace CatLib.Container
/// </summary>
internal sealed class MethodContainer
{
/// <summary>
/// Call method target map to method names.
/// </summary>
private readonly Dictionary<object, List<string>> targetToMethodsMappings;

/// <summary>
/// An map of the method bing data.
/// </summary>
private readonly Dictionary<string, MethodBind> methodMappings;

/// <summary>
/// The <see cref="Container"/> instnace.
/// </summary>
private readonly Container container;

/// <summary>
/// The sync lock.
/// </summary>
private readonly object syncRoot;

/// <summary>
Expand Down Expand Up @@ -133,9 +118,7 @@ public void Unbind(object target)

lock (syncRoot)
{
var methodBind = target as MethodBind;

if (methodBind != null)
if (target is MethodBind methodBind)
{
methodBind.Unbind();
return;
Expand Down Expand Up @@ -200,7 +183,6 @@ internal void Unbind(MethodBind methodBind)
/// <summary>
/// Create a method without not found exception.
/// </summary>
/// <param name="method">The method name.</param>
private static LogicException MakeMethodNotFoundException(string method)
{
return new LogicException($"Method [{method}] is not found.");
Expand All @@ -209,7 +191,6 @@ private static LogicException MakeMethodNotFoundException(string method)
/// <summary>
/// Remove all methods bound to the object.
/// </summary>
/// <param name="target">The object.</param>
private void UnbindWithObject(object target)
{
if (!targetToMethodsMappings.TryGetValue(target, out List<string> methods))
Expand Down
3 changes: 0 additions & 3 deletions src/CatLib.Core/Container/ParamsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ namespace CatLib.Container
[ExcludeFromCodeCoverage]
public sealed class ParamsCollection : IParams, IEnumerable<KeyValuePair<string, object>>
{
/// <summary>
/// The parameter mapping.
/// </summary>
private readonly IDictionary<string, object> table;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/CatLib.Core/EventDispatcher/IEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

using System;
using System.Collections.Generic;

namespace CatLib.EventDispatcher
{
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/Support/Arr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public static int Unshift<T>(ref T[] source, params T[] elements)
/// <para>If the value is set to a negative number, then remove the <paramref name="length"/> absolute position from the back to the front to delete.</para>
/// <para>If the value is not set, then all elements from the position set by the <paramref name="start"/> parameter to the end of the array are returned.</para>
/// </param>
/// <returns>反转的数组.</returns>
/// <returns>Returns inverted array.</returns>
public static T[] Reverse<T>(T[] source, int start = 0, int? length = null)
{
Guard.Requires<ArgumentNullException>(source != null);
Expand Down
Loading