diff --git a/src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt b/src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt index ef3f1302f11..164f08cae36 100644 --- a/src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt +++ b/src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt @@ -483,6 +483,7 @@ namespace Akka.Actor public override Akka.Actor.ActorPath Parent { get; } public override Akka.Actor.ActorPath Root { get; } public override int CompareTo(Akka.Actor.ActorPath other) { } + public override int GetHashCode() { } public override Akka.Actor.ActorPath WithUid(long uid) { } } public sealed class CoordinatedShutdown : Akka.Actor.IExtension diff --git a/src/core/Akka/Actor/ActorPath.cs b/src/core/Akka/Actor/ActorPath.cs index 7ef5b3d2884..b26b8cf4858 100644 --- a/src/core/Akka/Actor/ActorPath.cs +++ b/src/core/Akka/Actor/ActorPath.cs @@ -121,7 +121,7 @@ public static bool IsValidPathElement(string s) { return false; } - return !s.StartsWith("$") && Validate(s.ToCharArray(), s.Length); + return !s.StartsWith("$") && Validate(s); } private static bool IsValidChar(char c) => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || @@ -130,8 +130,9 @@ private static bool IsValidChar(char c) => (c >= 'a' && c <= 'z') || (c >= 'A' & private static bool IsHexChar(char c) => (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9'); - private static bool Validate(IReadOnlyList chars, int len) + private static bool Validate(string chars) { + int len = chars.Length; var pos = 0; while (pos < len) { @@ -182,8 +183,6 @@ protected ActorPath(ActorPath parentPath, string name, long uid) public long Uid { get; } internal static readonly string[] EmptyElements = { }; - internal static readonly string[] SystemElements = { "system" }; - internal static readonly string[] UserElements = { "user" }; /// /// Gets the elements. @@ -239,7 +238,23 @@ public bool Equals(ActorPath other) if (other == null) return false; - return Address.Equals(other.Address) && Elements.SequenceEqual(other.Elements); + if (!Address.Equals(other.Address)) + return false; + + ActorPath a = this; + ActorPath b = other; + for (;;) + { + if (ReferenceEquals(a, b)) + return true; + else if (a == null || b == null) + return false; + else if (a.Name != b.Name) + return false; + + a = a.Parent; + b = b.Parent; + } } /// @@ -654,6 +669,19 @@ public override ActorPath WithUid(long uid) return new ChildActorPath(_parent, _name, uid); } + /// + public override int GetHashCode() + { + unchecked + { + var hash = 17; + hash = (hash * 23) ^ Address.GetHashCode(); + for (ActorPath p = this; p != null; p = p.Parent) + hash = (hash * 23) ^ p.Name.GetHashCode(); + return hash; + } + } + /// public override int CompareTo(ActorPath other) {