ceki        2004/12/29 04:02:33

  Modified:    src/java/org/apache/log4j/spi LoggingEvent.java
  Log:
  Theoretically safer but still quick LoggingEvent.equals
  
  Revision  Changes    Path
  1.73      +27 -14    
logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
  
  Index: LoggingEvent.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- LoggingEvent.java 28 Dec 2004 20:14:16 -0000      1.72
  +++ LoggingEvent.java 29 Dec 2004 12:02:33 -0000      1.73
  @@ -111,18 +111,13 @@
      */
     private transient LoggerRepository loggerRepository;
   
  -  /**
  -   * <p>
  -   * The logger name.
  -   * </p>
  -   *
  -   * @deprecated This field will be marked as private in future releases.
  -   *             Please do not access it directly. Use the [EMAIL PROTECTED]
  -   *             #getLoggerName} method instead.
  -   */
  -  //the 'logger name' variable name ("categoryName") must remain the same as 
prior versions in order
  -  //to maintain serialization compatibility with log4j 1.2.8
  -  private String categoryName;
  + 
  +   // The logger name.
  +   //
  +   // the 'logger name' variable name ("categoryName") must remain the same 
  +   // as prior versions in order to maintain serialization compatibility 
with 
  +   // log4j 1.2.8
  +   private String categoryName;
   
     /**
      * Level of logging event. Level cannot be serializable because it is a
  @@ -309,8 +304,26 @@
         return false;
       }
   
  -    // If both the timestamp and the sequenceNumber are equal than the 
objects
  -    // are assumed to be equal.
  +    // at this point, the probability of the two events being equal is
  +    // extremely high. The next few test is optimized to take advantage of
  +    // this knowlege. (We only compare string lengths instead of invoking
  +    // string.equals which is much slower when the two string are equal.
  +    
  +    if(categoryName != null &&  rEvent.categoryName != null) {
  +      if(categoryName.length() != rEvent.categoryName.length()) {
  +        return false;
  +      }
  +    } else if(categoryName != rEvent.categoryName) {
  +      // of categoryNames is null while the other is not, they can't possibly
  +      // be equal
  +      return false;
  +    }
  +
  + 
  +
  +    
  +    // If timestamp, sequenceNumber and categoryName length are equal than 
the 
  +    // events are assumed to be equal.
       return true;
     }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to