Browse Source

HPCC-12351 Switch various StringBuffers to StringAttrs

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 10 years ago
parent
commit
377d8cd092

+ 1 - 3
common/dllserver/thorplugin.cpp

@@ -63,8 +63,6 @@ const char * SimplePluginCtx::ctxQueryProp(const char *propName) const
 class HelperDll : public CInterface, implements ILoadedDllEntry
 {
     SharedObject so;
-    StringBuffer version;
-    StringBuffer fileLocation;
     StringAttr name;
     Linked<const IFileIO> dllFile;
     bool logLoad;
@@ -144,7 +142,7 @@ bool HelperDll::IsShared()
 
 const char * HelperDll::queryVersion() const
 {
-    return version.str();
+    return "";
 }
 
 void HelperDll::logLoaded()

+ 4 - 2
common/thorhelper/layouttrans.cpp

@@ -75,9 +75,11 @@ MappingLevel::MappingLevel(FieldMapping::List & _mappings) : topLevel(true), map
 
 MappingLevel::MappingLevel(MappingLevel * parent, char const * name, FieldMapping::List & _mappings) : topLevel(false), mappings(_mappings)
 {
+    StringBuffer fullScope;
     if(!parent->topLevel)
-        scope.append(parent->scope).append(scopeSeparator);
-    scope.append(name);
+        fullScope.append(parent->scope).append(scopeSeparator);
+    fullScope.append(name);
+    scope.setown(fullScope.detach());
 }
 
 void MappingLevel::calculateMappings(IDefRecordElement const * diskRecord, unsigned numKeyedDisk, IDefRecordElement const * activityRecord, unsigned numKeyedActivity)

+ 1 - 1
common/thorhelper/layouttrans.ipp

@@ -90,7 +90,7 @@ private:
 
 private:
     bool topLevel;
-    StringBuffer scope;
+    StringAttr scope;
     FieldMapping::List & mappings;
 };
 

+ 5 - 3
common/thorhelper/roxiedebug.cpp

@@ -870,11 +870,13 @@ DebugActivityRecord::DebugActivityRecord (IActivityBase *_activity, unsigned _it
 {
     localCycles = 0;
     totalCycles = 0;
-    idText.append(activity->queryId());
+    StringBuffer fullId;
+    fullId.append(activity->queryId());
     if (iteration || channel) 
-        idText.appendf(".%d", iteration);
+        fullId.appendf(".%d", iteration);
     if (channel) 
-        idText.appendf("#%d", channel);
+        fullId.appendf("#%d", channel);
+    idText.set(fullId);
 }
 
 void DebugActivityRecord::outputId(IXmlWriter *output, const char *fieldName)

+ 1 - 1
common/thorhelper/roxiedebug.hpp

@@ -173,7 +173,7 @@ public:
     unsigned channel;
     unsigned sequence;
     IArrayOf<IDebugGraphManager> childGraphs;
-    StringBuffer idText;
+    StringAttr idText;
     Owned<IProperties> properties;
 
     IMPLEMENT_IINTERFACE;

+ 9 - 6
common/thorhelper/roxiehelper.cpp

@@ -632,21 +632,24 @@ void CSafeSocket::setHttpMode(const char *queryName, bool arrayMode, TextMarkupF
     assertex(contentHead.length()==0 && contentTail.length()==0);
     if (mlFmt==MarkupFmt_JSON)
     {
-        contentHead.append("{");
-        contentTail.append("}");
+        contentHead.set("{");
+        contentTail.set("}");
     }
     else
     {
-        contentHead.append(
+        StringBuffer headText, tailText;
+        headText.append(
             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
             "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
             "<soap:Body>");
         if (arrayMode)
         {
-            contentHead.append("<").append(queryName).append("ResponseArray>");
-            contentTail.append("</").append(queryName).append("ResponseArray>");
+            headText.append("<").append(queryName).append("ResponseArray>");
+            tailText.append("</").append(queryName).append("ResponseArray>");
         }
-        contentTail.append("</soap:Body></soap:Envelope>");
+        tailText.append("</soap:Body></soap:Envelope>");
+        contentHead.set(headText);
+        contentTail.set(tailText);
     }
 }
 

+ 2 - 2
common/thorhelper/roxiehelper.hpp

@@ -90,8 +90,8 @@ protected:
     bool httpMode;
     bool heartbeat;
     TextMarkupFormat mlFmt;
-    StringBuffer contentHead;
-    StringBuffer contentTail;
+    StringAttr contentHead;
+    StringAttr contentTail;
     PointerArray queued;
     UnsignedArray lengths;
     unsigned sent;

+ 6 - 6
common/thorhelper/thorsoapcall.cpp

@@ -83,8 +83,8 @@ class Url : public CInterface, implements IInterface
 public:
     IMPLEMENT_IINTERFACE;
 
-    StringBuffer method;
-    StringBuffer host;
+    StringAttr method;
+    StringAttr host;
     unsigned port;
     StringBuffer path;
     StringBuffer userPasswordPair;
@@ -155,7 +155,7 @@ public:
         {
             *p = 0;
             p += 3; // skip past the colon-slash-slash
-            method.append(urltext);
+            method.set(urltext);
             urltext = p;
         }
         else
@@ -179,7 +179,7 @@ public:
 
             port = atoi(p);
 
-            host.append(urltext);
+            host.set(urltext);
 
             if ((p = strchr(p, '/')) != NULL)
                 path.append(p);
@@ -201,12 +201,12 @@ public:
                 *p = 0;
                 p++;
 
-                host.append(urltext);
+                host.set(urltext);
                 path.append("/").append(p);
             }
             else
             {
-                host.append(urltext);
+                host.set(urltext);
                 path.append("/");
             }
         }

+ 11 - 6
common/workunit/referencedfilelist.cpp

@@ -127,7 +127,10 @@ public:
     ReferencedFile(const char *lfn, const char *sourceIP, const char *srcCluster, const char *prefix, bool isSubFile, unsigned _flags, const char *_pkgid, bool noDfs, bool calcSize)
     : flags(_flags), pkgid(_pkgid), noDfsResolution(noDfs), calcFileSize(calcSize), fileSize(0), numParts(0)
     {
-        logicalName.set(skipForeign(lfn, &daliip)).toLowerCase();
+        StringBuffer logicalNameText, daliipText;
+        logicalNameText.set(skipForeign(lfn, &daliipText)).toLowerCase();
+        logicalName.set(logicalNameText);
+        daliip.set(daliipText);
         if (daliip.length())
             flags |= RefFileForeign;
         else
@@ -157,7 +160,7 @@ public:
     virtual unsigned getFlags() const {return flags;}
     virtual const SocketEndpoint &getForeignIP(SocketEndpoint &ep) const
     {
-        if (flags & RefFileForeign && daliip.length())
+        if ((flags & RefFileForeign) && daliip.length())
             ep.set(daliip.str());
         else
             ep.set(NULL);
@@ -176,10 +179,10 @@ public:
     }
 
 public:
-    StringBuffer logicalName;
+    StringAttr logicalName;
     StringAttr pkgid;
-    StringBuffer daliip;
-    StringBuffer filePrefix;
+    StringAttr daliip;
+    StringAttr filePrefix;
     StringAttr fileSrcCluster;
     __int64 fileSize;
     unsigned numParts;
@@ -347,7 +350,9 @@ IPropertyTree *ReferencedFile::getSpecifiedOrRemoteFileTree(IUserDescriptor *use
     Owned<IPropertyTree> fileTree = getRemoteFileTree(user, remote, remotePrefix);
     if (!fileTree)
         return NULL;
-    remote->endpoint().getUrlStr(daliip);
+    StringBuffer daliipText;
+    remote->endpoint().getUrlStr(daliipText);
+    daliip.set(daliipText);
     filePrefix.set(remotePrefix);
     return fileTree.getClear();
 }

+ 5 - 3
common/workunit/workunit.cpp

@@ -603,8 +603,8 @@ public:
 
 public:
     StringAttr creator;
-    StringBuffer scope;
     StringAttr description;
+    StringBuffer scope;
     StatisticMeasure measure;
     StatisticKind kind;
     StatisticCreatorType creatorType;
@@ -882,7 +882,7 @@ private:
 class CLocalWUAppValue : public CInterface, implements IConstWUAppValue
 {
     Owned<IPropertyTree> p;
-    StringBuffer prop;
+    StringAttr prop;
 public:
     IMPLEMENT_IINTERFACE;
     CLocalWUAppValue(IPropertyTree *p,unsigned child);
@@ -8776,7 +8776,9 @@ void CLocalWUException::setExceptionColumn(unsigned c)
 
 CLocalWUAppValue::CLocalWUAppValue(IPropertyTree *props,unsigned child): p(props)
 {
-    prop.append("*[").append(child).append("]");
+    StringBuffer propPath;
+    propPath.append("*[").append(child).append("]");
+    prop.setown(propPath);
 }
 
 IStringVal & CLocalWUAppValue::getApplication(IStringVal & str) const

+ 1 - 1
common/wuwebview/wuwebview.cpp

@@ -58,7 +58,7 @@ public:
             if (queryname)
                 buffer.append(queryname);
             buffer.append("Response");
-            if (flags & WWV_INCL_NAMESPACES && ns.length())
+            if ((flags & WWV_INCL_NAMESPACES) && ns.length())
                 buffer.append(" xmlns=\"").append(ns.str()).append('\"');
             buffer.append('>');
         }

+ 0 - 1
dali/base/dasds.ipp

@@ -591,7 +591,6 @@ class CXPathIterator : public CInterface, implements IPropertyTreeIterator
     UnsignedArray childPositions;
     IPropertyTree *currentChild;
     IPTIteratorCodes flags;
-    StringBuffer currentPath;
     bool validateServerIds;
 public:
     IMPLEMENT_IINTERFACE;

+ 4 - 2
ecl/eclagent/eclagent.ipp

@@ -853,7 +853,7 @@ private:
         unsigned sourceId;
         unsigned outputIndex;
 
-        StringBuffer edgeId;
+        StringAttr edgeId;
 
     public:
         IMPLEMENT_IINTERFACE;
@@ -861,7 +861,9 @@ private:
         LegacyInputProbe(IHThorInput *_in, EclSubGraph *_owner, unsigned _sourceId, int outputidx)
             : in(_in), owner(_owner), sourceId(_sourceId), outputIndex(outputidx)
         {
-            edgeId.append(_sourceId).append("_").append(outputidx);
+            StringBuffer edgeIdText;
+            edgeIdText.append(_sourceId).append("_").append(outputidx);
+            edgeId.setown(edgeIdText);
             maxRowSize = 0;
         }
 

+ 6 - 2
ecl/hql/hqlir.cpp

@@ -1128,13 +1128,17 @@ class TextIRBuilder : public CInterfaceOf<IEclBuilder>
         Definition(const char * prefix, id_t _id, bool expandInline) : id(_id)
         {
             if (!expandInline)
-                idText.append("%").append(prefix).append(id);
+            {
+                StringBuffer s;
+                s.append("%").append(prefix).append(id);
+                idText.setown(s);
+            }
         }
 
         inline bool expandInline() const { return idText.length() == 0; }
 
     public:
-        StringBuffer idText;
+        StringAttr idText;
         id_t id;
     };
 

+ 6 - 6
esp/bindings/http/platform/httpbinding.cpp

@@ -120,12 +120,12 @@ EspHttpBinding::EspHttpBinding(IPropertyTree* tree, const char *bindname, const
         if (!bnd_cfg->getProp("@baseFilesPath", m_filespath))
             m_filespath.append(getCFD()).append("./files/");
 
-        m_host.append(bnd_cfg->queryProp("@netAddress"));
+        m_host.set(bnd_cfg->queryProp("@netAddress"));
         m_port = bnd_cfg->getPropInt("@port");
 
         const char *realm = bnd_cfg->queryProp("@realm");
         if (realm)
-            m_realm.append(realm);
+            m_realm.set(realm);
         else
         {
             StringBuffer xpath;
@@ -136,7 +136,7 @@ EspHttpBinding::EspHttpBinding(IPropertyTree* tree, const char *bindname, const
                 const char *type = bindings->query().queryProp("@type");
                 if (type && !stricmp(type, "ws_smcSoapBinding"))
                 {
-                    m_realm.append("EclWatch");
+                    m_realm.set("EclWatch");
                     break;
                 }
             }
@@ -156,7 +156,7 @@ EspHttpBinding::EspHttpBinding(IPropertyTree* tree, const char *bindname, const
                     }
                 }
                 
-                m_realm.append((realm) ? realm : "EspServices");
+                m_realm.set((realm) ? realm : "EspServices");
             }
         }
 
@@ -177,8 +177,8 @@ EspHttpBinding::EspHttpBinding(IPropertyTree* tree, const char *bindname, const
         Owned<IPropertyTree> authcfg = bnd_cfg->getPropTree("Authenticate");
         if(authcfg != NULL)
         {
-            authcfg->getProp("@type", m_authtype);
-            authcfg->getProp("@method", m_authmethod);
+            m_authtype.set(authcfg->queryProp("@type"));
+            m_authmethod.set(authcfg->queryProp("@method"));
             PROGLOG("Authenticate method=%s", m_authmethod.str());
             if(stricmp(m_authmethod.str(), "LdapSecurity") == 0)
             {

+ 15 - 15
esp/bindings/http/platform/httpbinding.hpp

@@ -30,9 +30,9 @@
 class CMethodInfo : public CInterface
 {
 public:
-    StringBuffer m_label;
-    StringBuffer m_requestLabel;
-    StringBuffer m_responseLabel;
+    StringAttr m_label;
+    StringAttr m_requestLabel;
+    StringAttr m_responseLabel;
 
     //StringBuffer m_securityTag;
     //StringBuffer m_optionalTag;
@@ -43,9 +43,9 @@ public:
     IMPLEMENT_IINTERFACE;
     CMethodInfo(const char * label, const char * req, const char * resp) //, const char *sectag, const char *optag,const char* minver=NULL, const char* maxver=NULL)
     {
-        m_label.append(label);
-        m_requestLabel.append(req);
-        m_responseLabel.append(resp);
+        m_label.set(label);
+        m_requestLabel.set(req);
+        m_responseLabel.set(resp);
         /*
         if (sectag)
             m_securityTag.append(sectag);
@@ -58,9 +58,9 @@ public:
 
     CMethodInfo(CMethodInfo &src)
     {
-        m_label.append(src.m_label);
-        m_requestLabel.append(src.m_requestLabel);
-        m_responseLabel.append(src.m_responseLabel);
+        m_label.set(src.m_label);
+        m_requestLabel.set(src.m_requestLabel);
+        m_responseLabel.set(src.m_responseLabel);
     };
 };
 
@@ -119,8 +119,8 @@ class esp_http_decl EspHttpBinding :
     implements IEspWsdlSections
 {
 private:
-    StringBuffer            m_host;
-    StringBuffer            m_realm;
+    StringAttr              m_host;
+    StringAttr              m_realm;
     unsigned short          m_port;
     bool                    m_viewConfig;
     bool                    m_formOptions;
@@ -129,8 +129,8 @@ private:
 
     HINSTANCE               m_hSecDll;
 
-    StringBuffer            m_authtype;
-    StringBuffer            m_authmethod;
+    StringAttr              m_authtype;
+    StringAttr              m_authmethod;
     StringBuffer            m_reqPath;
     StringBuffer            m_filespath;
     StringBuffer            m_wsdlAddress;
@@ -159,13 +159,13 @@ public:
     const char *getHost(){return m_host.str();}
     unsigned short getPort(){return m_port;}
 
-    void setRealm(const char *realm){m_realm.clear().append((realm) ? realm : "EspService");}
+    void setRealm(const char *realm){m_realm.set((realm) ? realm : "EspService");}
     const char *getRealm(){return m_realm.str();}
     const char* getChallengeRealm() {return m_challenge_realm.str();}
     double getWsdlVersion(){return m_wsdlVer;}
     void setWsdlVersion(double ver){m_wsdlVer=ver;}
     const char *getWsdlAddress(){return m_wsdlAddress.str();}
-    void setWsdlAddress(const char *wsdladdress){m_wsdlAddress.clear().append(wsdladdress);}
+    void setWsdlAddress(const char *wsdladdress){m_wsdlAddress.set(wsdladdress);}
 
     virtual void setRequestPath(const char *path);
     virtual bool rootAuthRequired();

+ 10 - 7
esp/bindings/http/platform/httptransport.cpp

@@ -1087,7 +1087,7 @@ StringBuffer& CHttpRequest::getMethod(StringBuffer & method)
 
 void CHttpRequest::setMethod(const char* method)
 {
-    m_httpMethod.clear().append(method);
+    m_httpMethod.set(method);
 }
 
 StringBuffer& CHttpRequest::getPath(StringBuffer & path)
@@ -1097,7 +1097,7 @@ StringBuffer& CHttpRequest::getPath(StringBuffer & path)
 
 void CHttpRequest::setPath(const char* path)
 {
-    m_httpPath.clear().append(path);
+    m_httpPath.set(path);
 }
 
 void CHttpRequest::parseQueryString(const char* querystr)
@@ -1363,6 +1363,7 @@ void CHttpRequest::parseEspPathInfo()
             m_sstype=(m_queryparams && m_queryparams->hasProp("main")) ? sub_serv_main : sub_serv_root;
         else
         {
+            //MORE: With a couple of changes there would be need to clone pathstr
             char *pathstr = strdup(m_httpPath.str());
             char *finger = pathstr;
             
@@ -1398,23 +1399,25 @@ void CHttpRequest::parseEspPathInfo()
                         if (pathex)
                         {
                             *pathex=0;
-                            m_espPathEx.append(pathex+1);
+                            m_espPathEx.set(pathex+1);
                         }
                             
                         *thumb=0;
-                        m_espMethodName.append(++thumb);
-                        const char *tail = strrchr(thumb, '.');
+                        const char * method = thumb+1;
+                        const char *tail = strrchr(method, '.');
                         ESPSerializationFormat fmt = lookupResponseFormatByExtension(tail);
                         if (fmt!=ESPSerializationANY)
                         {
                             m_context->setResponseFormat(fmt);
-                            m_espMethodName.setLength(tail-thumb);
+                            m_espMethodName.set(method, tail-method);
                         }
+                        else
+                            m_espMethodName.set(method);
                     }
                     else 
                         missingTrailSlash = true; 
 
-                    m_espServiceName.append(finger);
+                    m_espServiceName.set(finger);
                 }
             }
             

+ 6 - 6
esp/bindings/http/platform/httptransport.ipp

@@ -282,13 +282,13 @@ const char* getSubServiceDesc(sub_service stype);
 class CHttpRequest : public CHttpMessage
 {
 private:
-    StringBuffer    m_httpMethod;
-    StringBuffer    m_httpPath;
-    bool            m_pathIsParsed;
-    StringBuffer    m_espServiceName;
-    StringBuffer    m_espMethodName;
-    StringBuffer    m_espPathEx;
+    StringAttr    m_httpMethod;
+    StringAttr    m_httpPath;
+    StringAttr    m_espServiceName;
+    StringAttr    m_espMethodName;
+    StringAttr    m_espPathEx;
     sub_service     m_sstype;
+    bool            m_pathIsParsed;
     bool            m_authrequired;
     int             m_MaxRequestEntityLength;
     ESPSerializationFormat respSerializationFormat;

+ 13 - 20
esp/services/ws_machine/ws_machineService.hpp

@@ -187,25 +187,20 @@ public:
 
 class CProcessData : public CInterface
 {
-    StringBuffer    m_type;
-    StringBuffer    m_name;
-    StringBuffer    m_path;
+    StringAttr    m_type;
+    StringAttr    m_name;
+    StringAttr    m_path;
     unsigned        m_processNumber;
     bool            m_multipleInstances;     //required from ProcessFilter in environment.xml
 
-    StringBuffer    m_pid;
-    StringBuffer    m_upTime;
+    StringAttr    m_pid;
+    StringAttr    m_upTime;
     set<string>     m_dependencies;
 public:
 IMPLEMENT_IINTERFACE;
 
 	CProcessData()
     {
-        m_name.clear();
-        m_type.clear();
-        m_path.clear();
-        m_pid.clear();
-        m_upTime.clear();
         m_processNumber = 0;
         m_multipleInstances = false;
         m_dependencies.clear();
@@ -214,11 +209,9 @@ IMPLEMENT_IINTERFACE;
     CProcessData(const char* name, const char* type, const char* path, unsigned processNumber):
         m_processNumber(processNumber)
     {
-        m_name = name;
-        m_type = type;
-        m_path = path;
-        m_pid.clear();
-        m_upTime.clear();
+        m_name.set(name);
+        m_type.set(type);
+        m_path.set(path);
         m_multipleInstances = false;
         m_dependencies.clear();
     }
@@ -226,7 +219,7 @@ IMPLEMENT_IINTERFACE;
 
     void setName(const char* name)
     {
-        m_name.clear().append(name);
+        m_name.set(name);
     }
 
     const char* getName()
@@ -236,7 +229,7 @@ IMPLEMENT_IINTERFACE;
 
     void setType(const char* type)
     {
-        m_type.clear().append(type);
+        m_type.set(type);
     }
 
     const char* getType()
@@ -246,7 +239,7 @@ IMPLEMENT_IINTERFACE;
 
     void setPath(const char* path)
     {
-        m_path.clear().append(path);
+        m_path.set(path);
     }
 
     const char* getPath()
@@ -256,7 +249,7 @@ IMPLEMENT_IINTERFACE;
 
     void setPID(const char* pid)
     {
-        m_pid.clear().append(pid);
+        m_pid.set(pid);
     }
 
     const char* getPID()
@@ -266,7 +259,7 @@ IMPLEMENT_IINTERFACE;
 
     void setUpTime(const char* upTime)
     {
-        m_upTime.clear().append(upTime);
+        m_upTime.set(upTime);
     }
 
     const char* getUpTime()

+ 16 - 0
system/jlib/jstring.cpp

@@ -1258,6 +1258,22 @@ void StringAttr::setown(const char * _text)
   text = (char *)_text;
 }
 
+void StringAttr::set(const StringBuffer & source)
+{
+    if (source.length())
+        set(source.str());
+    else
+        clear();
+}
+
+void StringAttr::setown(StringBuffer & source)
+{
+    if (source.length())
+        setown(source.detach());
+    else
+        clear();
+}
+
 void StringAttr::toLowerCase()
 {
     if (text)

+ 3 - 0
system/jlib/jstring.hpp

@@ -251,11 +251,14 @@ public:
     inline const char * get(void) const         { return text; }
     inline size32_t     length() const          { return text ? (size32_t)strlen(text) : 0; }
     inline bool isEmpty() const                 { return !text||!*text; } // faster than (length==0)
+    inline const char * str(void) const         { return text ? text : ""; } // safe form (doesn't return NULL)
     inline const char * sget(void) const        { return text ? text : ""; } // safe form of get (doesn't return NULL)
 
     void         set(const char * _text);
     void         setown(const char * _text);
     void         set(const char * _text, unsigned _len);
+    void         set(const StringBuffer & source);
+    void         setown(StringBuffer & source);
     void         toLowerCase();
     void         toUpperCase();