~kinkie/squid/stringng

« back to all changes in this revision

Viewing changes to src/SBuf.cci

  • Committer: Francesco Chemolli
  • Date: 2011-04-27 15:00:38 UTC
  • Revision ID: kinkie@squid-cache.org-20110427150038-kp2qdna80hrv236p
Steamlined SBuf::rawSpace and implemented its companion SBuf::forceSize() method.
Clarified documentation.
Implemented size argument to cow()

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
 
116
116
/**
117
117
 * copy-on-write: make sure that we are the only holder of the backing store.
118
 
 * If not, reallocate.
 
118
 * If not, reallocate. If a new size is specified, and it is greater than the
 
119
 * current length, the backing store will be extended as needed
119
120
 * \retval false no grow was needed
120
121
 * \retval true had to copy
121
122
 */
122
123
bool
123
 
SBuf::cow()
 
124
SBuf::cow(SBuf::size_type newsize)
124
125
{
125
126
    debugs(SBUF_DEBUGSECTION,DBG_DATA,MYNAME);
126
 
    if (store_->RefCountCount() == 1) {
 
127
    if (newsize==npos || newsize < length())
 
128
        newsize=length();
 
129
 
 
130
    if (store_->RefCountCount() == 1 && newsize==length()) {
127
131
        debugs(SBUF_DEBUGSECTION,DBG_DATA,"no cow needed");
128
132
        ++stats.cowFast;
129
133
        return false;
130
134
    }
131
 
    reAlloc(length());
 
135
    reAlloc(newsize);
132
136
    return true;
133
137
}
134
138