mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1087834 - Reduce heap churn involving |input_overflow_buf_|. r=billm.
--HG-- extra : rebase_source : f842309c5d75479fefc266d405c0b8aceb7c247f
This commit is contained in:
parent
e396733de9
commit
f50b6cd934
@ -383,14 +383,20 @@ bool Channel::ChannelImpl::EnqueueHelloMessage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
ClearAndShrink(std::string& s, size_t capacity)
|
||||
void Channel::ChannelImpl::ClearAndShrinkInputOverflowBuf()
|
||||
{
|
||||
// This swap trick is the closest thing C++ has to a guaranteed way to
|
||||
// shrink the capacity of a string.
|
||||
std::string tmp;
|
||||
tmp.reserve(capacity);
|
||||
s.swap(tmp);
|
||||
// If input_overflow_buf_ has grown, shrink it back to its normal size.
|
||||
static size_t previousCapacityAfterClearing = 0;
|
||||
if (input_overflow_buf_.capacity() > previousCapacityAfterClearing) {
|
||||
// This swap trick is the closest thing C++ has to a guaranteed way
|
||||
// to shrink the capacity of a string.
|
||||
std::string tmp;
|
||||
tmp.reserve(Channel::kReadBufferSize);
|
||||
input_overflow_buf_.swap(tmp);
|
||||
previousCapacityAfterClearing = input_overflow_buf_.capacity();
|
||||
} else {
|
||||
input_overflow_buf_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool Channel::ChannelImpl::Connect() {
|
||||
@ -519,7 +525,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
|
||||
} else {
|
||||
if (input_overflow_buf_.size() >
|
||||
static_cast<size_t>(kMaximumMessageSize - bytes_read)) {
|
||||
ClearAndShrink(input_overflow_buf_, Channel::kReadBufferSize);
|
||||
ClearAndShrinkInputOverflowBuf();
|
||||
CHROMIUM_LOG(ERROR) << "IPC message is too big";
|
||||
return false;
|
||||
}
|
||||
@ -628,7 +634,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
|
||||
}
|
||||
}
|
||||
if (end == p) {
|
||||
ClearAndShrink(input_overflow_buf_, Channel::kReadBufferSize);
|
||||
ClearAndShrinkInputOverflowBuf();
|
||||
} else if (!overflowp) {
|
||||
// p is from input_buf_
|
||||
input_overflow_buf_.assign(p, end - p);
|
||||
|
@ -59,6 +59,8 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
|
||||
bool ProcessIncomingMessages();
|
||||
bool ProcessOutgoingMessages();
|
||||
|
||||
void ClearAndShrinkInputOverflowBuf();
|
||||
|
||||
// MessageLoopForIO::Watcher implementation.
|
||||
virtual void OnFileCanReadWithoutBlocking(int fd);
|
||||
virtual void OnFileCanWriteWithoutBlocking(int fd);
|
||||
|
Loading…
Reference in New Issue
Block a user