]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Move SBuf<->String conversion to own header.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 24 Feb 2016 18:12:43 +0000 (19:12 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 24 Feb 2016 18:12:43 +0000 (19:12 +0100)
15 files changed:
src/HttpRequest.cc
src/Makefile.am
src/MemObject.h
src/acl/HttpHeaderData.cc
src/acl/Note.cc
src/acl/NoteData.cc
src/adaptation/Iterator.cc
src/ipc/TypedMsgHdr.cc
src/mgr/ActionParams.cc
src/sbuf/Makefile.am
src/sbuf/SBuf.cc
src/sbuf/SBuf.h
src/sbuf/SBufStringConvert.h [new file with mode: 0644]
src/tests/stub_SBuf.cc
src/tests/testSBuf.cc

index 869b50730911ac072beea17e7d286c6317230a11..5460e4fa98f16db1494aa06018cf9433717cf8fb 100644 (file)
@@ -25,6 +25,7 @@
 #include "HttpRequest.h"
 #include "log/Config.h"
 #include "MemBuf.h"
+#include "sbuf/SBufStringConvert.h"
 #include "SquidConfig.h"
 #include "Store.h"
 #include "URL.h"
@@ -660,7 +661,7 @@ HttpRequest::storeId()
 {
     if (store_id.size() != 0) {
         debugs(73, 3, "sent back store_id: " << store_id);
-        return SBuf(store_id);
+        return SBuf(StringToSBuf(store_id));
     }
     debugs(73, 3, "sent back effectiveRequestUrl: " << effectiveRequestUri());
     return effectiveRequestUri();
index c5e5d0b79a655c458b507077c2eb894ec46a9e22..33afd36fe27499b091b23762feaf34686a20fcb1 100644 (file)
@@ -412,6 +412,7 @@ squid_SOURCES = \
        send-announce.cc \
        SBufStatsAction.h \
        SBufStatsAction.cc \
+  sbuf/SBufStringConvert.h \
        $(SNMP_SOURCE) \
        SquidMath.h \
        SquidMath.cc \
index 9b644e0fbc1bf7a27f1e8573499c9acbff33c728..6bca732361e86f49924eec78577185d9553315c4 100644 (file)
@@ -13,6 +13,7 @@
 #include "dlink.h"
 #include "http/RequestMethod.h"
 #include "RemovalPolicy.h"
+#include "SquidString.h"
 #include "stmem.h"
 #include "StoreIOBuffer.h"
 #include "StoreIOState.h"
index 9d4c661434be4d9efcc52b375090cd7cc1a17efc..db1fbd22e8d753ca6b4a2c51a9052a0e4028bbb1 100644 (file)
@@ -18,6 +18,7 @@
 #include "Debug.h"
 #include "HttpHeaderTools.h"
 #include "sbuf/SBuf.h"
+#include "sbuf/SBufStringConvert.h"
 
 /* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
  * selected header from a given request.
@@ -51,7 +52,7 @@ ACLHTTPHeaderData::match(HttpHeader* hdr)
             return false;
     }
 
-    SBuf cvalue(value);
+    SBuf cvalue(StringToSBuf(value));
     return regex_rule->match(cvalue.c_str());
 }
 
index a2140fefcdb89ee854489c72cd95d32d98b9325a..50f666e420e60c0577924f12c6754197b6828137 100644 (file)
@@ -14,6 +14,7 @@
 #include "HttpRequest.h"
 #include "Notes.h"
 #include "parser/Tokenizer.h"
+#include "sbuf/SBufStringConvert.h"
 
 int
 ACLNoteStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
@@ -36,7 +37,7 @@ ACLNoteStrategy::matchNotes(ACLData<MatchType> *noteData, const NotePairs *note,
     for (auto &entry: note->entries) {
         if (delimiters) {
             NotePairs::Entry e(entry->name.termedBuf(), "");
-            Parser::Tokenizer t(SBuf(entry->value));
+            Parser::Tokenizer t(SBuf(StringToSBuf(entry->value)));
             SBuf s;
             while (t.token(s, *delimiters)) {
                 e.value = s.c_str();
index a987b5f7998964e697cd089e2aad931012ce0182..d65b1f2534b099f83e34c958e34a7fba4ab3ea80 100644 (file)
@@ -13,6 +13,7 @@
 #include "acl/StringData.h"
 #include "ConfigParser.h"
 #include "Debug.h"
+#include "sbuf/SBufStringConvert.h"
 #include "wordlist.h"
 
 ACLNoteData::ACLNoteData() : values(new ACLStringData)
@@ -38,7 +39,7 @@ SBufList
 ACLNoteData::dump() const
 {
     SBufList sl;
-    sl.push_back(SBuf(name));
+    sl.push_back(StringToSBuf(name));
 #if __cplusplus >= 201103L
     sl.splice(sl.end(), values->dump());
 #else
index 5af1fe175cb3f209af10239962e19a3e4ed2cf3c..37bce3483d3db9c8ef7f4ead2a1a84d1de973f81 100644 (file)
@@ -19,6 +19,7 @@
 #include "HttpMsg.h"
 #include "HttpReply.h"
 #include "HttpRequest.h"
+#include "sbuf/SBufStringConvert.h"
 
 Adaptation::Iterator::Iterator(
     HttpMsg *aMsg, HttpRequest *aCause,
@@ -62,7 +63,7 @@ void Adaptation::Iterator::start()
             request = theCause;
         Must(request);
         Adaptation::History::Pointer ah = request->adaptHistory(true);
-        SBuf gid(theGroup->id);
+        SBuf gid(StringToSBuf(theGroup->id));
         ah->recordAdaptationService(gid);
     }
 
@@ -102,7 +103,7 @@ void Adaptation::Iterator::step()
 
     if (Adaptation::Config::needHistory) {
         Adaptation::History::Pointer ah = request->adaptHistory(true);
-        SBuf uid(thePlan.current()->cfg().key);
+        SBuf uid(StringToSBuf(thePlan.current()->cfg().key));
         ah->recordAdaptationService(uid);
     }
 
index aa7b6a3b51b362de2712ed962d10e78bb59b01fb..36bba1f1722541684f37a076c7d0b81a3fb9dfda 100644 (file)
@@ -11,6 +11,7 @@
 #include "squid.h"
 #include "base/TextException.h"
 #include "ipc/TypedMsgHdr.h"
+#include "SquidString.h"
 #include "tools.h"
 
 #include <cstring>
index 4ea288f3c9398a8dd8ebb8ad5708d9f27cec2f68..6488a06218f987791e719f7a87b59780e4f74beb 100644 (file)
@@ -12,6 +12,7 @@
 #include "base/TextException.h"
 #include "ipc/TypedMsgHdr.h"
 #include "mgr/ActionParams.h"
+#include "sbuf/SBufStringConvert.h"
 
 Mgr::ActionParams::ActionParams(): httpMethod(Http::METHOD_NONE)
 {
@@ -38,7 +39,7 @@ void
 Mgr::ActionParams::pack(Ipc::TypedMsgHdr &msg) const
 {
     msg.putString(httpUri);
-    String foo(httpMethod.image().toString());
+    String foo(SBufToString(httpMethod.image()));
     msg.putString(foo);
     msg.putPod(httpFlags);
     msg.putString(httpOrigin);
index 982371f97cf3b3d24c90c410b91ca3657ce26876..fd3731318ec09186f39a106863ca06f247d5b940 100644 (file)
@@ -25,4 +25,4 @@ libsbuf_la_SOURCES = \
        SBufExceptions.h \
        SBufList.cc \
        SBufList.h \
-       SBufStream.h
\ No newline at end of file
+       SBufStream.h
index 05803bc216c1e402915f9148d99722d4ef1120ab..1e75cc883168f01775e748b667d0400d7852a00f 100644 (file)
@@ -37,7 +37,7 @@ const SBuf::size_type SBuf::npos;
 const SBuf::size_type SBuf::maxSize;
 
 SBufStats::SBufStats()
-    : alloc(0), allocCopy(0), allocFromString(0), allocFromCString(0),
+    : alloc(0), allocCopy(0), allocFromCString(0),
       assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
       getChar(0), compareSlow(0), compareFast(0), copyOut(0),
       rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0), scanf(0),
@@ -49,7 +49,6 @@ SBufStats::operator +=(const SBufStats& ss)
 {
     alloc += ss.alloc;
     allocCopy += ss.allocCopy;
-    allocFromString += ss.allocFromString;
     allocFromCString += ss.allocFromCString;
     assignFast += ss.assignFast;
     clear += ss.clear;
@@ -92,23 +91,12 @@ SBuf::SBuf(const SBuf &S)
     ++stats.live;
 }
 
-SBuf::SBuf(const String &S)
-    : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    debugs(24, 8, id << " created from string");
-    assign(S.rawBuf(), S.size());
-    ++stats.alloc;
-    ++stats.allocFromString;
-    ++stats.live;
-}
-
 SBuf::SBuf(const std::string &s)
     : store_(GetStorePrototype()), off_(0), len_(0)
 {
     debugs(24, 8, id << " created from std::string");
     lowAppend(s.data(),s.length());
     ++stats.alloc;
-    ++stats.allocFromString;
     ++stats.live;
 }
 
@@ -882,7 +870,6 @@ SBufStats::dump(std::ostream& os) const
     os <<
        "SBuf stats:\nnumber of allocations: " << alloc <<
        "\ncopy-allocations: " << allocCopy <<
-       "\ncopy-allocations from SquidString: " << allocFromString <<
        "\ncopy-allocations from C String: " << allocFromCString <<
        "\nlive references: " << live <<
        "\nno-copy assignments: " << assignFast <<
@@ -947,15 +934,6 @@ SBuf::checkAccessBounds(size_type pos) const
         throw OutOfBoundsException(*this, pos, __FILE__, __LINE__);
 }
 
-String
-SBuf::toString() const
-{
-    String rv;
-    rv.limitInit(buf(), length());
-    ++stats.copyOut;
-    return rv;
-}
-
 /** re-allocate the backing store of the SBuf.
  *
  * If there are contents in the SBuf, they will be copied over.
index 8bb77ab8ab7e87bef11d1b33b4a1986ef67dee62..f275fc7894105e3ed1bb5e848262c8b493eea3de 100644 (file)
@@ -16,7 +16,6 @@
 #include "globals.h"
 #include "sbuf/MemBlob.h"
 #include "SBufExceptions.h"
-#include "SquidString.h"
 
 #include <climits>
 #include <cstdarg>
@@ -50,7 +49,6 @@ class SBufStats
 public:
     uint64_t alloc; ///<number of calls to SBuf constructors
     uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
-    uint64_t allocFromString; ///<number of copy-allocations from Strings
     uint64_t allocFromCString; ///<number of copy-allocations from c-strings
     uint64_t assignFast; ///<number of no-copy assignment operations
     uint64_t clear; ///<number of clear operations
@@ -162,12 +160,6 @@ public:
     explicit SBuf(const char *S, size_type n);
     explicit SBuf(const char *S);
 
-    /** Constructor: import SquidString, copying contents.
-     *
-     * This method will be removed once SquidString has gone.
-     */
-    explicit SBuf(const String &S);
-
     /// Constructor: import std::string. Contents are copied.
     explicit SBuf(const std::string &s);
 
@@ -639,12 +631,6 @@ public:
     /// converts all characters to upper case; \see man toupper(3)
     void toUpper();
 
-    /** String export function
-     * converts the SBuf to a legacy String, by copy.
-     * \deprecated
-     */
-    String toString() const;
-
     /// std::string export function
     std::string toStdString() const { return std::string(buf(),length()); }
 
diff --git a/src/sbuf/SBufStringConvert.h b/src/sbuf/SBufStringConvert.h
new file mode 100644 (file)
index 0000000..15434f1
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_SBUF_SBUFSTRING_H_
+#define SQUID_SRC_SBUF_SBUFSTRING_H_
+
+#include "SBuf.h"
+#include "SquidString.h"
+
+/// create a new SBuf from a String
+inline SBuf
+StringToSBuf(const String &s)
+{
+    return SBuf(s.rawBuf(), s.size());
+}
+
+/// create a new String from a SBuf
+inline String
+SBufToString(const SBuf &s)
+{
+    String rv;
+    rv.limitInit(s.rawContent(), s.length());
+    return rv;
+}
+
+#endif /* SQUID_SRC_SBUF_SBUFSTRING_H_ */
index 6be715719c5058b0380c5720b633c5b87241adfd..a5de68ead671c67b4baabf7fef0c6bcc41f05269 100644 (file)
@@ -27,7 +27,6 @@ SBuf::SBuf() {}
 SBuf::SBuf(const SBuf &S) {}
 SBuf::SBuf(const char *S, size_type n) {}
 SBuf::SBuf(const char *S) {}
-SBuf::SBuf(const String &S) {}
 SBuf::SBuf(const std::string &s) {}
 SBuf::~SBuf() {}
 SBuf& SBuf::assign(const SBuf &S) STUB_RETVAL(*this)
@@ -66,5 +65,4 @@ SBuf::size_type SBuf::findFirstNotOf(const CharacterSet &set, size_type startPos
 int SBuf::scanf(const char *format, ...) STUB_RETVAL(-1)
 void SBuf::toLower() STUB
 void SBuf::toUpper() STUB
-String SBuf::toString() const STUB_RETVAL(String(""))
 
index 0b896e3520f226ee90ef7701e21ec42aa04cb877..f22943bdf044c1e048a541fc943e86c3b822f188 100644 (file)
@@ -12,7 +12,6 @@
 #include "sbuf/SBufAlgos.h"
 #include "SBufFindTest.h"
 #include "sbuf/SBufStream.h"
-#include "SquidString.h"
 #include "testSBuf.h"
 #include "unitTestMain.h"
 
@@ -116,13 +115,6 @@ testSBuf::testSBufConstructDestruct()
         CPPUNIT_ASSERT_EQUAL(s4,s3);
     }
 
-    // TEST: go via SquidString adapters.
-    {
-        String str(fox);
-        SBuf s1(str);
-        CPPUNIT_ASSERT_EQUAL(literal,s1);
-    }
-
     // TEST: go via std::string adapter.
     {
         std::string str(fox);