From: Francesco Chemolli Date: Wed, 24 Feb 2016 18:12:43 +0000 (+0100) Subject: Move SBuf<->String conversion to own header. X-Git-Tag: SQUID_4_0_8~60^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d1c9fe8605934f008cb15f366d1883187bbbcfb;p=thirdparty%2Fsquid.git Move SBuf<->String conversion to own header. --- diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 869b507309..5460e4fa98 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -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(); diff --git a/src/Makefile.am b/src/Makefile.am index c5e5d0b79a..33afd36fe2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -412,6 +412,7 @@ squid_SOURCES = \ send-announce.cc \ SBufStatsAction.h \ SBufStatsAction.cc \ + sbuf/SBufStringConvert.h \ $(SNMP_SOURCE) \ SquidMath.h \ SquidMath.cc \ diff --git a/src/MemObject.h b/src/MemObject.h index 9b644e0fbc..6bca732361 100644 --- a/src/MemObject.h +++ b/src/MemObject.h @@ -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" diff --git a/src/acl/HttpHeaderData.cc b/src/acl/HttpHeaderData.cc index 9d4c661434..db1fbd22e8 100644 --- a/src/acl/HttpHeaderData.cc +++ b/src/acl/HttpHeaderData.cc @@ -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()); } diff --git a/src/acl/Note.cc b/src/acl/Note.cc index a2140fefcd..50f666e420 100644 --- a/src/acl/Note.cc +++ b/src/acl/Note.cc @@ -14,6 +14,7 @@ #include "HttpRequest.h" #include "Notes.h" #include "parser/Tokenizer.h" +#include "sbuf/SBufStringConvert.h" int ACLNoteStrategy::match(ACLData * &data, ACLFilledChecklist *checklist, ACLFlags &flags) @@ -36,7 +37,7 @@ ACLNoteStrategy::matchNotes(ACLData *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(); diff --git a/src/acl/NoteData.cc b/src/acl/NoteData.cc index a987b5f799..d65b1f2534 100644 --- a/src/acl/NoteData.cc +++ b/src/acl/NoteData.cc @@ -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 diff --git a/src/adaptation/Iterator.cc b/src/adaptation/Iterator.cc index 5af1fe175c..37bce3483d 100644 --- a/src/adaptation/Iterator.cc +++ b/src/adaptation/Iterator.cc @@ -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); } diff --git a/src/ipc/TypedMsgHdr.cc b/src/ipc/TypedMsgHdr.cc index aa7b6a3b51..36bba1f172 100644 --- a/src/ipc/TypedMsgHdr.cc +++ b/src/ipc/TypedMsgHdr.cc @@ -11,6 +11,7 @@ #include "squid.h" #include "base/TextException.h" #include "ipc/TypedMsgHdr.h" +#include "SquidString.h" #include "tools.h" #include diff --git a/src/mgr/ActionParams.cc b/src/mgr/ActionParams.cc index 4ea288f3c9..6488a06218 100644 --- a/src/mgr/ActionParams.cc +++ b/src/mgr/ActionParams.cc @@ -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); diff --git a/src/sbuf/Makefile.am b/src/sbuf/Makefile.am index 982371f97c..fd3731318e 100644 --- a/src/sbuf/Makefile.am +++ b/src/sbuf/Makefile.am @@ -25,4 +25,4 @@ libsbuf_la_SOURCES = \ SBufExceptions.h \ SBufList.cc \ SBufList.h \ - SBufStream.h \ No newline at end of file + SBufStream.h diff --git a/src/sbuf/SBuf.cc b/src/sbuf/SBuf.cc index 05803bc216..1e75cc8831 100644 --- a/src/sbuf/SBuf.cc +++ b/src/sbuf/SBuf.cc @@ -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. diff --git a/src/sbuf/SBuf.h b/src/sbuf/SBuf.h index 8bb77ab8ab..f275fc7894 100644 --- a/src/sbuf/SBuf.h +++ b/src/sbuf/SBuf.h @@ -16,7 +16,6 @@ #include "globals.h" #include "sbuf/MemBlob.h" #include "SBufExceptions.h" -#include "SquidString.h" #include #include @@ -50,7 +49,6 @@ class SBufStats public: uint64_t alloc; ///