提交 3907fccf 编写于 作者: S Steffen Forkmann 提交者: Kevin Ransom (msft)

Don't convert attributes to array and then to list (#3159)

* Don't convert attributes to array and then to list

* Don't convert attributes to array and then to list
上级 c5482ca9
......@@ -1588,7 +1588,7 @@ and [<Sealed>] ILTypeDefs(f : unit -> (string list * string * ILAttributes * Laz
t)
member x.AsArray = [| for (_,_,_,ltd) in array.Value -> ltd.Force() |]
member x.AsList = x.AsArray |> Array.toList
member x.AsList = [ for (_,_,_,ltd) in array.Value -> ltd.Force() ]
interface IEnumerable with
member x.GetEnumerator() = ((x :> IEnumerable<ILTypeDef>).GetEnumerator() :> IEnumerator)
......
......@@ -854,6 +854,7 @@ type ILAttribute =
[<NoEquality; NoComparison; Sealed>]
type ILAttributes =
member AsArray : ILAttribute []
member AsList : ILAttribute list
/// Method parameters and return values.
......
......@@ -2718,18 +2718,17 @@ let isILAttrib (tref:ILTypeRef) (attr: ILAttribute) =
// These linear iterations cost us a fair bit when there are lots of attributes
// on imported types. However this is fairly rare and can also be solved by caching the
// results of attribute lookups in the TAST
let HasILAttribute tref (attrs: ILAttributes) = List.exists (isILAttrib tref) attrs.AsList
let HasILAttribute tref (attrs: ILAttributes) = Array.exists (isILAttrib tref) attrs.AsArray
let HasILAttributeByName tname (attrs: ILAttributes) = List.exists (isILAttribByName ([],tname)) attrs.AsList
let HasILAttributeByName tname (attrs: ILAttributes) = Array.exists (isILAttribByName ([],tname)) attrs.AsArray
let TryDecodeILAttribute (g:TcGlobals) tref (attrs: ILAttributes) =
attrs.AsList |> List.tryPick(fun x -> if isILAttrib tref x then Some(decodeILAttribData g.ilg x) else None)
attrs.AsArray |> Array.tryPick (fun x -> if isILAttrib tref x then Some(decodeILAttribData g.ilg x) else None)
// This one is done by name to ensure the compiler doesn't take a dependency on dereferencing a type that only exists in .NET 3.5
let ILThingHasExtensionAttribute (attrs : ILAttributes) =
attrs.AsList
|> List.exists (fun attr ->
attr.Method.EnclosingType.TypeSpec.Name = "System.Runtime.CompilerServices.ExtensionAttribute")
attrs.AsArray
|> Array.exists (fun attr -> attr.Method.EnclosingType.TypeSpec.Name = "System.Runtime.CompilerServices.ExtensionAttribute")
// F# view of attributes (these get converted to AbsIL attributes in ilxgen)
let IsMatchingFSharpAttribute g (AttribInfo(_,tcref)) (Attrib(tcref2,_,_,_,_,_,_)) = tyconRefEq g tcref tcref2
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册