IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 17, 2006, 3:59:13 PM (20 years ago)
Author:
Paul Price
Message:

No need to do psStringAlloc on empty string --- we can allocate
the string once we know the size: saves an allocation call.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psString.c

    r8232 r8415  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-08-08 23:32:23 $
     15 *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-08-18 01:59:13 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    108108    }
    109109
    110     if (!*dest) {
    111         *dest = psStringCopy("");
     110    if (*dest) {
     111        oldLength = strlen(*dest);
     112    } else {
    112113        oldLength = 0;
    113     } else {
    114         // size of existing string
    115         oldLength = strlen(*dest);
    116114    }
    117115
     
    128126    }
    129127
    130     // new string length (sans \0)
    131     length = oldLength + tailLength;
    132 
    133128    // realloc string to string + tail + \0
    134     *dest = psRealloc(*dest, length + 1);
     129    if (*dest) {
     130        *dest = psRealloc(*dest, oldLength + tailLength + 1);
     131    } else {
     132        *dest = psStringAlloc(oldLength + tailLength + 1);
     133    }
    135134
    136135    // append tail + \0
Note: See TracChangeset for help on using the changeset viewer.