You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2018/12/04 17:17:29 UTC

[GitHub] garydgregory commented on a change in pull request #244: New iso date time formats

garydgregory commented on a change in pull request #244: New iso date time formats
URL: https://github.com/apache/logging-log4j2/pull/244#discussion_r238757885
 
 

 ##########
 File path: log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
 ##########
 @@ -183,16 +218,27 @@ static FixedFormat lookupIgnoringNanos(final String pattern) {
             return null;
         }
 
-        private static int nanoStart(final String pattern) {
-            final int index = pattern.indexOf(SECOND_FRACTION_PATTERN);
-            if (index >= 0) {
-                for (int i = index + 1; i < pattern.length(); i++) {
+        private final static int[] EMPTY_RANGE = { -1, -1 };
+        
+        /**
+         * 
+         * @param pattern
+         * @return int[0] start index inclusive; int[1] end index exclusive
+         */
+        private static int[] nanoRange(final String pattern) {
+            final int indexStart = pattern.indexOf(SECOND_FRACTION_PATTERN);
+            int indexEnd = -1;
+            if (indexStart >= 0) {
+                indexEnd = pattern.indexOf('Z', indexStart);
+                indexEnd = indexEnd < 0 ? pattern.indexOf('X', indexStart) : indexEnd;
+                indexEnd = indexEnd < 0 ? pattern.length() : indexEnd; 
+                for (int i = indexStart + 1; i < indexEnd; i++) {
                     if (pattern.charAt(i) != SECOND_FRACTION_PATTERN) {
-                        return -1;
+                        return EMPTY_RANGE;
                     }
                 }
             }
-            return index;
+            return new int [] {indexStart, indexEnd};
 
 Review comment:
   Hi @remkop 
   
   Thank you for your review.
   
   Are you sure this really matters? This code only kicks in once per thread or when a configuration is created, not for each log event, so creating the array should not create garbage for each event.
   
   WDYT?
   
   Gary

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services