Commons JXPath
  1. Commons JXPath
  2. JXPATH-15

JXPathContextFactory doesn't cache most common result of search

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Nightly Builds
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      JXPathContextFactory's search for a factory class name caches all values
      returned in the search except the default value. This means that in the
      default case (which is the most common, obviously), the search is performed
      every time, which is quite expensive.

      this is the problem method:
      private static String findFactory(String property, String defaultFactory)

      note that it does not cache the value of defaultFactory in the foundFactory
      class variable when that is the value returned.

      suggest adding
      foundFactory = defaultFactory;
      return foundFactory;

      in place of
      return defaultFactory;

      at the end of this method.

        Activity

        Hide
        Dmitri Plotnikov added a comment -

        I fixed it basically as suggested. However, I would recommend using
        JXPathContext.newContext() instead of JXPathContextFactory.newInstance
        ().newInstance(), because the static JXPathContext.newContext() method uses
        additional cache. JXPathContextFactory caches the name of the factory class.
        JXPathContext statically caches the instance of factory. Thus, using
        JXPathContext.newContext() eliminates repeated allocation of the factory.

        Show
        Dmitri Plotnikov added a comment - I fixed it basically as suggested. However, I would recommend using JXPathContext.newContext() instead of JXPathContextFactory.newInstance ().newInstance(), because the static JXPathContext.newContext() method uses additional cache. JXPathContextFactory caches the name of the factory class. JXPathContext statically caches the instance of factory. Thus, using JXPathContext.newContext() eliminates repeated allocation of the factory.

          People

          • Assignee:
            Unassigned
            Reporter:
            Eric Friedman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development