commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils BeanUtils.java
Date Mon, 16 Dec 2002 00:29:48 GMT
craigmcc    2002/12/15 16:29:48

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        BeanUtils.java
  Log:
  Improve the performance of getArrayProperty() by using an array as the
  destination, rather than an ArrayList that is then converted to an array.
  
  PR: Bugzilla #15160
  Submitted by:	Ingo Struck <ingo at ingostruck.de>
  
  Revision  Changes    Path
  1.30      +16 -18    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java
  
  Index: BeanUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- BeanUtils.java	16 Dec 2002 00:21:02 -0000	1.29
  +++ BeanUtils.java	16 Dec 2002 00:29:48 -0000	1.30
  @@ -456,27 +456,25 @@
               Iterator items = ((Collection) value).iterator();
               while (items.hasNext()) {
                   Object item = items.next();
  -                if (item == null)
  +                if (item == null) {
                       values.add((String) null);
  -                else
  +                } else {
                       values.add(item.toString());
  +                }
               }
               return ((String[]) values.toArray(new String[values.size()]));
           } else if (value.getClass().isArray()) {
  -            ArrayList values = new ArrayList();
  -            try {
  -                int n = Array.getLength(value);
  -                for (int i = 0; i < n; i++) {
  -                    Object item = Array.get(value, i);
  -                    if (item == null)
  -                        values.add((String) null);
  -                    else
  -                        values.add(item.toString());
  +            int n = Array.getLength(value);
  +            String results[] = new String[n];
  +            for (int i = 0; i < n; i++) {
  +                Object item = Array.get(value, i);
  +                if (item == null) {
  +                    results[i] = null;
  +                } else {
  +                    results[i] = item.toString();
                   }
  -            } catch (ArrayIndexOutOfBoundsException e) {
  -                ;
               }
  -            return ((String[]) values.toArray(new String[values.size()]));
  +            return (results);
           } else {
               String results[] = new String[1];
               results[0] = value.toString();
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message