Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9
    • Fix Version/s: 3.3, 4.0-ALPHA
    • Component/s: core/index
    • Labels:
      None
    • Lucene Fields:
      New, Patch Available

      Description

      Applying the attached patch shows the improvements to DateTools.java that I think should be done. All logic that does anything at all is moved to instance methods of the inner class Resolution. I argue this is more object-oriented.

      1. In cases where Resolution is an argument to the method, I can simply invoke the appropriate call on the Resolution object. Formerly there was a big branch if/else.
      2. Instead of "synchronized" being used seemingly everywhere, synchronized is used to sync on the object that is not threadsafe, be it a DateFormat or Calendar instance.
      3. Since different DateFormat and Calendar instances are created per-Resolution, there is now less lock contention since threads using different resolutions will not use the same locks.
      4. The old implementation of timeToString rounded the time before formatting it. That's unnecessary since the format only includes the resolution desired.
      5. round() now uses a switch statement that benefits from fall-through (no break).

      Another debatable improvement that could be made is putting the resolution instances into an array indexed by format length. This would mean I could remove the switch in lookupResolutionByLength() and avoid the length constants there. Maybe that would be a bit too over-engineered when the switch is fine.

      1. cleanerDateTools.patch
        11 kB
        David Smiley
      2. LUCENE-1736_DateTools_improvements.patch
        8 kB
        David Smiley
      3. LUCENE-1736.patch
        8 kB
        Steve Rowe

        Activity

        Hide
        Steve Rowe added a comment -

        David, I tried to apply your patch, but it failed (using "patch") - maybe partly because the patch is in git format? I don't use git, so it's tough for me to review issues with git formatted patches.

        I went and looked at the DateTools.java and compared it to your patch, and things have changed significantly since you wrote the patch, especially as a result of Uwe's changes from LUCENE-1472. Could you take a look at that issue, see if it resolves (enough of) the problems you addressed in your patch to make this issue now obsolete? If not, could you regenerate the patch (diff/patch format please)?

        Show
        Steve Rowe added a comment - David, I tried to apply your patch, but it failed (using "patch") - maybe partly because the patch is in git format? I don't use git, so it's tough for me to review issues with git formatted patches. I went and looked at the DateTools.java and compared it to your patch, and things have changed significantly since you wrote the patch, especially as a result of Uwe's changes from LUCENE-1472 . Could you take a look at that issue, see if it resolves (enough of) the problems you addressed in your patch to make this issue now obsolete? If not, could you regenerate the patch (diff/patch format please)?
        Hide
        David Smiley added a comment -

        This is an updated patch.

        • The former "DateFormats" class was used as a value in a ThreadLocal which isn't a good idea as it hampers class reloading.
        • Improvements to a switch statement to benefit from fall-through.
        • Removed a pointless conversion to Calendar in timeToString()
        • Moved functionality to Resolution enum, and used arrays of Resolutions indexed by format length instead of large if-else or switch blocks for format & parse. The ramification is 48 fewer lines of code.
        Show
        David Smiley added a comment - This is an updated patch. The former "DateFormats" class was used as a value in a ThreadLocal which isn't a good idea as it hampers class reloading. Improvements to a switch statement to benefit from fall-through. Removed a pointless conversion to Calendar in timeToString() Moved functionality to Resolution enum, and used arrays of Resolutions indexed by format length instead of large if-else or switch blocks for format & parse. The ramification is 48 fewer lines of code.
        Hide
        Steve Rowe added a comment -

        David, this is your patch with a CHANGES.txt entry and a couple of comments added ("for javadocs" next to the two imports that are javadocs-only; and formatLen spelled out over the shared format string).

        Nice improvements. All tests pass.

        I plan on committing shortly.

        Show
        Steve Rowe added a comment - David, this is your patch with a CHANGES.txt entry and a couple of comments added ("for javadocs" next to the two imports that are javadocs-only; and formatLen spelled out over the shared format string). Nice improvements. All tests pass. I plan on committing shortly.
        Hide
        Steve Rowe added a comment -

        Committed:

        • r1132806: trunk
        • r1132812: branch_3x

        Thanks David!

        Show
        Steve Rowe added a comment - Committed: r1132806: trunk r1132812: branch_3x Thanks David!
        Hide
        Robert Muir added a comment -

        bulk close for 3.3

        Show
        Robert Muir added a comment - bulk close for 3.3

          People

          • Assignee:
            Steve Rowe
            Reporter:
            David Smiley
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development