SBufStats::SBufStats()
: alloc(0), allocCopy(0), allocFromString(0), allocFromCString(0),
- assignFast(0), clear(0), append(0), toStream(0), setChar(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),
caseChange(0), cowFast(0), cowSlow(0), live(0)
assignFast += ss.assignFast;
clear += ss.clear;
append += ss.append;
+ moves += ss.moves;
toStream += ss.toStream;
setChar += ss.setChar;
getChar += ss.getChar;
int
SBuf::compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const
{
- if (n != npos && (n > length() || n > S.length())) {
+// if (n != npos && (n > length() || n > S.length())) {
+ if (n != npos) {
debugs(24, 8, "length specified. substr and recurse");
return substr(0,n).compare(S.substr(0,n),isCaseSensitive);
}
debugs(24, 8, "result: " << rv);
return rv;
}
+ if (n <= length() || n <= S.length()) {
+ debugs(24, 8, "same contents and bounded length. Equal");
+ return 0;
+ }
if (length() == S.length()) {
- debugs(24, 8, "same contents and length. Equal");
+ debugs(24, 8, "same contents and same length. Equal");
return 0;
}
if (length() > S.length()) {
"\nno-copy assignments: " << assignFast <<
"\nclearing operations: " << clear <<
"\nappend operations: " << append <<
+ "\nmove operations: " << moves <<
"\ndump-to-ostream: " << toStream <<
"\nset-char: " << setChar <<
"\nget-char: " << getChar <<
uint64_t assignFast; ///<number of no-copy assignment operations
uint64_t clear; ///<number of clear operations
uint64_t append; ///<number of append operations
+ uint64_t moves; ///<number of move constructions/assignments
uint64_t toStream; ///<number of write operations to ostreams
uint64_t setChar; ///<number of calls to setAt
uint64_t getChar; ///<number of calls to at() and operator[]
SBuf();
SBuf(const SBuf &S);
SBuf(SBuf&& S) : store_(std::move(S.store_)), off_(S.off_), len_(S.len_) {
- S.store_=GetStorePrototype(); S.off_=0; S.len_=0;
+ S.store_=NULL; S.off_=0; S.len_=0; //RefCount supports NULL
}
/** Constructor: import c-style string
* \note bounds is 0 <= pos < length(); caller must pay attention to signedness
*/
explicit SBuf(const char *S, size_type n);
- explicit SBuf(const char *S) : SBuf(S,strlen(S)) {}
+ explicit SBuf(const char *S) : SBuf(S, npos) {}
/** Constructor: import SquidString, copying contents.
*
* Current SBuf will share backing store with the assigned one.
*/
SBuf& operator =(const SBuf & S) {return assign(S);}
+ SBuf& operator =(SBuf &&S) {
+ ++stats.moves;
+ if (this != &S) {
+ store_ = std::move(S.store_);
+ off_ = S.off_;
+ len_ = S.len_;
+ S.store_ = NULL; //RefCount supports NULL, and S is about to be destructed
+ S.off_ = 0;
+ S.len_ = 0;
+ }
+ return *this;
+ }
/** Import a c-string into a SBuf, copying the data.
*
* assign(stdstr.data(), stdstd.length())
*/
SBuf& assign(const char *S, size_type n);
- SBuf& assign(const char *S) {return assign(S,strlen(S));}
+ SBuf& assign(const char *S) {return assign(S,npos);}
/** Assignment operator. Copy a NULL-terminated c-style string into a SBuf.
*
* cstr_append(stdstr.data(), stdstd.length())
*/
SBuf& append(const char * S, size_type Ssize);
- SBuf& append(const char * S) { return append(S,strlen(S)); }
+ SBuf& append(const char * S) { return append(S,npos); }
/** Assignment operation with printf(3)-style definition
* \note arguments may be evaluated more than once, be careful
*/
int compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const;
int compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive) const {
- return compare(S, isCaseSensitive, S.length());
+ return compare(S, isCaseSensitive, npos);
}
/// shorthand version for compare()
return compare(S,caseSensitive,n);
}
inline int cmp(const SBuf &S) const {
- return compare(S,caseSensitive,S.length());
+ return compare(S,caseSensitive,npos);
}
/// shorthand version for case-insensitive compare()
return compare(S,caseInsensitive,n);
}
inline int caseCmp(const SBuf &S) const {
- return compare(S,caseInsensitive,S.length());
+ return compare(S,caseInsensitive,npos);
}
/// Comparison with a C-string.
int compare(const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const;
int compare(const char *s, const SBufCaseSensitive isCaseSensitive) const {
- return compare(s,isCaseSensitive,strlen(s));
+ return compare(s,isCaseSensitive,npos);
}
/// Shorthand version for C-string compare().
return compare(S,caseSensitive,n);
}
inline int cmp(const char *S) const {
- return compare(S,caseSensitive,strlen(S));
+ return compare(S,caseSensitive,npos);
}
/// Shorthand version for case-insensitive C-string compare().
return compare(S,caseInsensitive,n);
}
inline int caseCmp(const char *S) const {
- return compare(S,caseInsensitive,strlen(S));
+ return compare(S,caseInsensitive,npos);
}
/** check whether the entire supplied argument is a prefix of the SBuf.