Changeset 227 for trunk/foundation


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.

Location:
trunk/foundation
Files:
4 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
  • trunk/foundation/class_c/nomstring.c

    r209 r227  
    9090{
    9191  NOMStringData* nomThis=NOMStringGetData(nomSelf);
    92   PNOMString nomRetval=(PNOMString) NOMString_new(nomSelf, NULLHANDLE);
    93   GString* gStrTmp;
    9492
    95   gStrTmp=g_string_new(_gString->str);
    96   g_string_append(gStrTmp, chrString);
    97   NOMString_assignCString(nomRetval, gStrTmp->str, NULLHANDLE);
    98   g_string_free(gStrTmp, TRUE);
     93  g_string_append(_gString, chrString);
    9994
    100   return nomRetval;
     95  return nomSelf;
    10196}
    10297
     
    10499                                                         CORBA_Environment *ev)
    105100{
    106   /*  NOMStringData* nomThis=NOMStringGetData(nomSelf); */
    107 
    108101  return NOMString_appendCString(nomSelf, NOMString_queryCString(nomString, NULLHANDLE), NULLHANDLE);
    109102}
     
    112105                                                          CORBA_Environment *ev)
    113106{
    114 /* NOMStringData* nomThis=NOMStringGetData(nomSelf); */
    115 
    116107  return NOMString_prependCString(nomSelf, NOMString_queryCString(nomString, NULLHANDLE), NULLHANDLE);
    117108}
     
    120111{
    121112  NOMStringData* nomThis=NOMStringGetData(nomSelf);
    122   PNOMString nomRetval=(PNOMString)NOMString_new(nomSelf, NULLHANDLE);
    123   GString* gStrTmp;
     113  g_string_prepend(_gString, chrString);
    124114
    125   gStrTmp=g_string_new(_gString->str);
    126   g_string_prepend(gStrTmp, chrString);
    127   NOMString_assignCString(nomRetval, gStrTmp->str, NULLHANDLE);
    128   g_string_free(gStrTmp, TRUE);
    129 
    130   return nomRetval;
     115  return nomSelf;
    131116}
    132117
     
    142127{
    143128  NOMStringData* nomThis=NOMStringGetData(nomSelf);
    144   PNOMString nomRetval=(PNOMString)NOMString_new(nomSelf, NULLHANDLE);
    145   GString* gStrTmp;
    146129
    147   gStrTmp=g_string_new(_gString->str);
    148   g_string_truncate(gStrTmp, ulNewLen);
    149   NOMString_assignCString(nomRetval, gStrTmp->str, NULLHANDLE);
    150   g_string_free(gStrTmp, TRUE);
     130  g_string_truncate(_gString, ulNewLen);
    151131
    152   return nomRetval;
     132  return nomSelf;
    153133}
    154134
  • trunk/foundation/idl/nomfilepath.idl

    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) 2005-2006
     18* Portions created by the Initial Developer are Copyright (C) 2005-2007
    1919* the Initial Developer. All Rights Reserved.
    2020*
     
    4343/** \class NOMPath
    4444    NOMPath is a specialized string class for dealing with file or directory paths.
    45     As with NOMString the NOMPath class is always working on copies.
    4645 */
    4746interface NOMPath : NOMString
     
    5857     starts with a separator and the current path ends with a separator the ending separator
    5958     will be removed before appending.
     59     If no input path is given only a separator is appended if necessary.
    6060
    6161     \remark
     
    6464
    6565     \return
    66      The method returns a new NOMPath instance after appending.
     66     The method returns the same NOMPath instance after appending.
    6767
    6868     \sa append(), appendCString()
     
    7272  /**
    7373     Append a separator to the path. If the path already has a separator at the end this method
    74      does nothing other than returning a new path object. If the given path has zero length
    75      a path object only holding a separator is returned.
     74     does nothing other than returning the path object. If the given path has zero length
     75     the path object only holding a separator is returned.
     76
     77     \remark The returned string object is not newly allocated. Be aware that the string data
     78     held by the object may.
    7679
    7780     \return
    78      This method always returns a new instance of a NOMPath owned by the caller.
     81     This method returns the NOMPath. This is not a copy.
    7982
    8083     \sa append(), appendPath()
     
    8689
    8790     \return
    88      This method always returns a new instance of a NOMPath owned by the caller.
     91     This method returns the same instance of a NOMPath.
    8992
    9093     \sa appendSeparator()
  • trunk/foundation/idl/nomstring.idl

    r225 r227  
    4545    Methods are provided for common tasks when dealing with strings like inserting or
    4646    appending strings. A string object never can be empty. It always is a string which may have a length of zero.
    47     These methods are threadsafe by always working with copies.
    4847
    4948    Note that you don't have to delete a NOMString object. This is done by the garbage collector. Deleting
     
    8584     In most cases you rather want to use copyCString() instead.
    8685
    87      \return The C string representing the contents of the string object.
     86     \return The C string representing the contents of the string object. This is not a copy.
    8887
    8988     \sa copyCString()
     
    9392  /**
    9493     Add the NOMString nomString to the end of the string object.
     94
     95     \remark The returned string object is not newly allocated. Be aware that the string data
     96     held by the object is.
    9597
    9698     \param nomString A NOMString object to be put at the end of the string.
    9799     \return     
    98      The returned NOMString object is a new object which is owned by the caller.
     100     Modified NOMString object with the given string object appended. This is not a copy.
    99101
    100102     \sa appendCString(), prepend()
     
    103105
    104106  /**
    105      Prepend the NOMString \e nomString to the given string object and return a pointer to a
    106      new string object.
     107     Prepend the NOMString \e nomString to the given string object and return the modified
     108     NOMString.
     109
     110     \remark The returned string object is not newly allocated. Be aware that the string data
     111     held by the object is.
    107112
    108113     \param nomString A NOMString object to be put in front of the string.
    109114     \return
    110      The returned NOMString object is a new object which is owned by the caller.
     115     NOMString object with the string prepended. This is not a copy.
    111116
    112117     \sa prependCString()
     
    117122     Append the given C string to the end of the string held by the NOMString object.
    118123
     124     \remark The returned string object is not newly allocated. Be aware that the string data
     125     held by the object is.
     126
    119127     \param chrString A null terminated string.
    120128     \return
    121      The NOMString object is a new object which is owned by the caller.
     129     Modified NOMString object with the C string appended. This is not a copy.
    122130
    123131     \sa append(), prependCString()
     
    128136     Prepend the C string to the string object.
    129137
     138     \remark The returned string object is not newly allocated. Be aware that the string data
     139     held by the object is.
     140
    130141     \param chrString A null terminated string.
    131142     \return
    132      The NOMString object is a new object which is owned by the caller.
     143     Modified NOMString object with the C string prepended.  This is not a copy.
    133144
    134145     \sa appendCString(), prepend()
     
    144155     Cuts off the end of a string leaving the first ulNewLen characters.
    145156
    146      \return
    147      The returned NOMString object is a new object holding the truncated string
    148      which is owned by the caller.
     157     \remark The returned string object is not newly allocated. Be aware that the string data
     158     held by the object is.
     159
     160     \return
     161     Truncated NOMString object. This is not a copy.
    149162  */
    150163  PNOMString truncate(in unsigned long ulNewLen);
Note: See TracChangeset for help on using the changeset viewer.