开发者

How do I optimize schemaDocument.Namespaces code for performance?

开发者 https://www.devze.com 2023-01-11 11:16 出处:网络
I have this code that is called thousands of times and I need to optimize it for performance. I thought about caching xmlQualifiedNames but it\'s not good enough.

I have this code that is called thousands of times and I need to optimize it for performance. I thought about caching xmlQualifiedNames but it's not good enough. any ideas ?

    private static string GetPrefixForNamespace(string ns,  XmlSchema schemaDocument)
    {
        string prefix = null;
         XmlQualifiedName[] xmlQualifi开发者_如何学PythonedNames = schemaDocument.Namespaces.ToArray();
        foreach (XmlQualifiedName qn in xmlQualifiedNames)
        {
            if (ns == qn.Namespace)
            {
                prefix = qn.Name;
                break;
            }
        }

        return prefix;
    }


since you're looking for strings (Namespace) inside the xmlQualifiedNames, how about caching those?

Or using LINQ to search in them?

Or - depending on the kind of input you get - using memoization to speed up your calls (really just fancy caching) like in this article.


Stuff it in a Dictionary or Hashtable or even a some caching mechanism.

0

精彩评论

暂无评论...
验证码 换一张
取 消