From f7026b2ec82008096b20f4d4be49d7d102262495 Mon Sep 17 00:00:00 2001 From: Steve Hawley Date: Wed, 11 Dec 2024 14:00:58 -0500 Subject: [PATCH] Removed Contains --- .../src/Metadata/ITypeMetadataCache.cs | 21 ++++++---------- .../src/Metadata/TypeMetadataCache.cs | 25 ++++++------------- .../TypeMetadataTests/TypeMetadataTests.cs | 8 +----- 3 files changed, 15 insertions(+), 39 deletions(-) diff --git a/src/Swift.Runtime/src/Metadata/ITypeMetadataCache.cs b/src/Swift.Runtime/src/Metadata/ITypeMetadataCache.cs index c6abdc9d3c0..8a814c84c10 100644 --- a/src/Swift.Runtime/src/Metadata/ITypeMetadataCache.cs +++ b/src/Swift.Runtime/src/Metadata/ITypeMetadataCache.cs @@ -12,27 +12,20 @@ namespace Swift.Runtime; public interface ITypeMetadataCache { /// - /// Returns true if and only if the cache contains an entry for t - /// - /// The type to look up in the cache - /// true if and only if the cache contains t, false otherwise - bool Contains(Type type); - - /// - /// Returns true if the cache contains an entry for t and sets metadata to the resulting value, + /// Returns true if the cache contains an entry for type and sets metadata to the resulting value, /// otherwise it returns false and metadata will be null. /// - /// - /// + /// The type to look up in the cache + /// The resulting metadata if found /// true if the lookup was successful, false otherwise bool TryGet(Type type, [NotNullWhen(true)]out TypeMetadata? metadata); /// - /// Gets the TypeMetadata for the given Type t or if it is not present, + /// Gets the TypeMetadata for the given Type type or if it is not present, /// adds it to the cache using the given factory to generate the value. /// - /// - /// - /// The TypeMetadata associated with the give Type t + /// The type to look up in the cache + /// a factory to generate the TypeMetadata if not present + /// The TypeMetadata associated with the give Type type TypeMetadata GetOrAdd(Type type, Func metadataFactory); } \ No newline at end of file diff --git a/src/Swift.Runtime/src/Metadata/TypeMetadataCache.cs b/src/Swift.Runtime/src/Metadata/TypeMetadataCache.cs index 4e30f54b693..27fa94ed960 100644 --- a/src/Swift.Runtime/src/Metadata/TypeMetadataCache.cs +++ b/src/Swift.Runtime/src/Metadata/TypeMetadataCache.cs @@ -35,23 +35,12 @@ public TypeMetadataCache(IEnumerable<(Type, TypeMetadata)> initialValues) } } - /// - /// Returns true if and only if the cache contains an entry for t. - /// - /// The type to look up in the cache - /// true if and only if the cache contains t, false otherwise - public bool Contains(Type type) - { - return cache.ContainsKey(type); - } - - /// - /// Returns true if the cache contains an entry for t and sets metadata to the resulting value, + /// Returns true if the cache contains an entry for type and sets metadata to the resulting value, /// otherwise it returns false and metadata will be null. /// - /// - /// + /// The type to look up in the cache + /// The resulting metadata if found /// true if the lookup was successful, false otherwise public bool TryGet(Type type, [NotNullWhen(true)] out TypeMetadata? metadata) { @@ -68,12 +57,12 @@ public bool TryGet(Type type, [NotNullWhen(true)] out TypeMetadata? metadata) } /// - /// Gets the TypeMetadata for the given Type t or if it is not present, + /// Gets the TypeMetadata for the given Type type or if it is not present, /// adds it to the cache using the given factory to generate the value. /// - /// - /// - /// The TypeMetadata associated with the give Type t + /// The type to look up in the cache + /// a factory to generate the TypeMetadata if not present + /// The TypeMetadata associated with the give Type type public TypeMetadata GetOrAdd(Type type, Func metadataFactory) { return cache.GetOrAdd(type, metadataFactory); diff --git a/src/Swift.Runtime/tests/TypeMetadataTests/TypeMetadataTests.cs b/src/Swift.Runtime/tests/TypeMetadataTests/TypeMetadataTests.cs index 6688e0a8339..b9ca9017f88 100644 --- a/src/Swift.Runtime/tests/TypeMetadataTests/TypeMetadataTests.cs +++ b/src/Swift.Runtime/tests/TypeMetadataTests/TypeMetadataTests.cs @@ -37,12 +37,6 @@ static TypeMetadata MakePhonyMetadata(int value) return (TypeMetadata)(ci.Invoke(new object[] { p })); } - [Fact] - public static void CacheDoesntContain() - { - Assert.False(TypeMetadata.Cache.Contains(typeof(System.EventArgs))); - } - [Fact] public static void CacheWorks() { @@ -51,7 +45,7 @@ public static void CacheWorks() { return fakeMeta; }); - Assert.True(TypeMetadata.Cache.Contains(typeof(System.Convert))); + Assert.True(TypeMetadata.Cache.TryGet(typeof(System.Convert), out var result)); } [Fact]