jdk/src/share/classes/java/lang/AbstractStringBuilder.java
changeset 7020 25638687fe82
parent 6295 91f1c55cf47e
child 7668 d4a77089c587
equal deleted inserted replaced
7019:f2f6b61d34ac 7020:25638687fe82
    98      * method takes no action and simply returns.
    98      * method takes no action and simply returns.
    99      *
    99      *
   100      * @param   minimumCapacity   the minimum desired capacity.
   100      * @param   minimumCapacity   the minimum desired capacity.
   101      */
   101      */
   102     public void ensureCapacity(int minimumCapacity) {
   102     public void ensureCapacity(int minimumCapacity) {
   103         ensureCapacityInternal(minimumCapacity);
   103         if (minimumCapacity > 0)
       
   104             ensureCapacityInternal(minimumCapacity);
   104     }
   105     }
   105 
   106 
   106     /**
   107     /**
   107      * This method has the same contract as ensureCapacity, but is
   108      * This method has the same contract as ensureCapacity, but is
   108      * never synchronized.
   109      * never synchronized.
   109      */
   110      */
   110     private void ensureCapacityInternal(int minimumCapacity) {
   111     private void ensureCapacityInternal(int minimumCapacity) {
       
   112         // overflow-conscious code
   111         if (minimumCapacity - value.length > 0)
   113         if (minimumCapacity - value.length > 0)
   112             expandCapacity(minimumCapacity);
   114             expandCapacity(minimumCapacity);
   113     }
   115     }
   114 
   116 
   115     /**
   117     /**