Merge pull request #19525 from mgravell/mgravell/remove-timespec-box

csharp: Remove a double-box on Timespec
reviewable/pr19588/r5
Jan Tattermusch 5 years ago committed by GitHub
commit 4a2f2dd1f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      src/csharp/Grpc.Core/Internal/Timespec.cs

@ -25,8 +25,49 @@ namespace Grpc.Core.Internal
/// gpr_timespec from grpc/support/time.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Timespec
internal struct Timespec : IEquatable<Timespec>
{
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
public override bool Equals(object obj)
{
return obj is Timespec && Equals((Timespec)obj);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
public override int GetHashCode()
{
unchecked
{
const int Prime = 373587911;
int i = (int)clock_type;
i = (i * Prime) ^ tv_nsec;
i = (i * Prime) ^ tv_nsec.GetHashCode();
return i;
}
}
/// <summary>
/// Returns the full type name of this instance.
/// </summary>
public override string ToString()
{
return typeof(Timespec).FullName;
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
public bool Equals(Timespec other)
{
return this.clock_type == other.clock_type
&& this.tv_nsec == other.tv_nsec
&& this.tv_sec == other.tv_sec;
}
const long NanosPerSecond = 1000 * 1000 * 1000;
const long NanosPerTick = 100;
const long TicksPerSecond = NanosPerSecond / NanosPerTick;

Loading…
Cancel
Save