private void ConstructFastPathTable()
 {
     this.noTemplateHasQueryPart = true;
     foreach (KeyValuePair <UriTemplate, object> pair in this.templates)
     {
         UriTemplate key = pair.Key;
         if (!UriTemplateHelpers.CanMatchQueryTrivially(key))
         {
             this.noTemplateHasQueryPart = false;
         }
         if (key.HasNoVariables && !key.HasWildcard)
         {
             if (this.fastPathTable == null)
             {
                 this.fastPathTable = new Dictionary <string, FastPathInfo>();
             }
             Uri    uri     = key.BindByPosition(this.originalUncanonicalizedBaseAddress, new string[0]);
             string uriPath = UriTemplateHelpers.GetUriPath(uri);
             if (!this.fastPathTable.ContainsKey(uriPath))
             {
                 FastPathInfo info = new FastPathInfo();
                 if (this.ComputeRelativeSegmentsAndLookup(uri, info.RelativePathSegments, info.Candidates))
                 {
                     info.Freeze();
                     this.fastPathTable.Add(uriPath, info);
                 }
             }
         }
     }
 }
        private bool FastComputeRelativeSegmentsAndLookup(Uri uri, out Collection <string> relativePathSegments, out IList <UriTemplateTableMatchCandidate> candidates)
        {
            string       uriPath = UriTemplateHelpers.GetUriPath(uri);
            FastPathInfo info    = null;

            if ((this.fastPathTable != null) && this.fastPathTable.TryGetValue(uriPath, out info))
            {
                relativePathSegments = info.RelativePathSegments;
                candidates           = info.Candidates;
                return(true);
            }
            relativePathSegments = new Collection <string>();
            candidates           = new Collection <UriTemplateTableMatchCandidate>();
            return(this.SlowComputeRelativeSegmentsAndLookup(uri, uriPath, relativePathSegments, candidates));
        }
Ejemplo n.º 3
0
        // this method checks the literal cache for a match if none, goes through the slower path of cracking the segments
        bool FastComputeRelativeSegmentsAndLookup(Uri uri, out Collection <string> relativePathSegments,
                                                  out IList <UriTemplateTableMatchCandidate> candidates)
        {
            // Consider fast-path and lookup
            // return false if not under base uri
            string       uriPath = UriTemplateHelpers.GetUriPath(uri);
            FastPathInfo fpInfo  = null;

            if ((this.fastPathTable != null) && this.fastPathTable.TryGetValue(uriPath, out fpInfo))
            {
                relativePathSegments = fpInfo.RelativePathSegments;
                candidates           = fpInfo.Candidates;
                VerifyThatFastPathAndSlowPathHaveSameResults(uri, relativePathSegments, candidates);
                return(true);
            }
            else
            {
                relativePathSegments = new Collection <string>();
                candidates           = new Collection <UriTemplateTableMatchCandidate>();
                return(SlowComputeRelativeSegmentsAndLookup(uri, uriPath, relativePathSegments, candidates));
            }
        }
Ejemplo n.º 4
0
 void ConstructFastPathTable()
 {
     this.noTemplateHasQueryPart = true;
     foreach (KeyValuePair <UriTemplate, object> kvp in this.templates)
     {
         UriTemplate ut = kvp.Key;
         if (!UriTemplateHelpers.CanMatchQueryTrivially(ut))
         {
             this.noTemplateHasQueryPart = false;
         }
         if (ut.HasNoVariables && !ut.HasWildcard)
         {
             // eligible for fast path
             if (this.fastPathTable == null)
             {
                 this.fastPathTable = new Dictionary <string, FastPathInfo>();
             }
             Uri    uri     = ut.BindByPosition(this.originalUncanonicalizedBaseAddress);
             string uriPath = UriTemplateHelpers.GetUriPath(uri);
             if (this.fastPathTable.ContainsKey(uriPath))
             {
                 // nothing to do, we've already seen it
             }
             else
             {
                 FastPathInfo fpInfo = new FastPathInfo();
                 if (ComputeRelativeSegmentsAndLookup(uri, fpInfo.RelativePathSegments,
                                                      fpInfo.Candidates))
                 {
                     fpInfo.Freeze();
                     this.fastPathTable.Add(uriPath, fpInfo);
                 }
             }
         }
     }
 }