Ignore:
Timestamp:
Feb 4, 2007, 10:51:43 PM (19 years ago)
Author:
cinc
Message:

Changed string and path classes not to return always copies but only when necessary.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/foundation/class_c/nomfilepath.c

    r225 r227  
    1616* The Initial Developer of the Original Code is
    1717* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
    18 * Portions created by the Initial Developer are Copyright (C) 2006
     18* Portions created by the Initial Developer are Copyright (C) 2006-2007
    1919* the Initial Developer. All Rights Reserved.
    2020*
     
    5555  added to the path prior to appending. If the given string starts with a separator and the current
    5656  path ends with a separator the ending separator will be removed before appending.
     57  If no input path is given only a separator is appended if necessary.
    5758
    5859  Note that there's no check if the input string is an absolute path. So if an absolute path is given as
     
    7273    return NOMPath_appendSeparator(nomSelf, ev);
    7374
     75  /* This is not a copy */
    7476  chrTemp=NOMPath_queryCString(nomPath, NULLHANDLE);
    7577  if(G_DIR_SEPARATOR==chrTemp[0])
    7678    np=NOMPath_stripSeparator(nomSelf, ev);
    77   else{
     79  else
    7880    np=NOMPath_appendSeparator(nomSelf, ev); /* Make sure current path has a separator */
    79   }
    8081
    8182  return (NOMPath*) NOMPath_append((NOMString*) np, (NOMString*)nomPath, NULLHANDLE);
     
    8485/**
    8586  Append a separator to the path. If the path already has a separator at the end this method does
    86   nothing other than returning a new path object. If the given path has zero length a path object
     87  nothing other than returning the path object. If the given path has zero length the path object
    8788  only holding a separator is returned.
    8889 
     
    9495  gulong len;
    9596
     97  /* Return only a separator */
    9698  if((len=NOMPath_length((NOMString*)nomSelf, ev))==0)
    9799    return (NOMPath*)NOMPath_appendCString((NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
    98100
     101  /* Add a separator */
    99102  if(G_DIR_SEPARATOR!=chrTemp[len-1])
    100103    return (NOMPath*)NOMPath_appendCString( (NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
    101104
    102   return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
     105  return nomSelf;
    103106}
    104107
     
    106109  Strips the path separator from the end of a path if there's one.
    107110
    108   This method always returns a new instance of a NOMPath owned by the caller.
     111  This method returns the same instance of a NOMPath.
    109112 */
    110113NOM_Scope PNOMPath NOMLINK impl_NOMPath_stripSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
     
    114117
    115118  if((len=NOMPath_length((NOMString*)nomSelf, NULLHANDLE))==0)
    116     return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
    117 
     119    return nomSelf;
     120
     121  /* This is not a copy */
    118122  chrTemp=NOMPath_queryCString((NOMString*)nomSelf, NULLHANDLE);
    119123
     
    121125    return (NOMPath*)NOMPath_truncate( (NOMString*)nomSelf, len-1, NULLHANDLE);
    122126
    123   return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
     127  return nomSelf;
    124128}
    125129
Note: See TracChangeset for help on using the changeset viewer.