rendered paste bodyFrom 9404ad8fe9f3eaaafcd9513378a1413ef91d528c Mon Sep 17 00:00:00 2001
From: Markus Goetz <Markus.Goetz@nokia.com>
Date: Mon, 14 Dec 2009 12:39:46 +0100
Subject: [PATCH] Pre-allocate memory in ResourceLoader
Reviewed-by: pending
---
.../webkit/WebCore/loader/ResourceLoader.cpp | 12 +++++++++---
.../webkit/WebCore/platform/SharedBuffer.cpp | 6 ++++++
.../webkit/WebCore/platform/SharedBuffer.h | 2 ++
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/3rdparty/webkit/WebCore/loader/ResourceLoader.cpp b/src/3rdparty/webkit/WebCore/loader/ResourceLoader.cpp
index 9244cf0..2b7e0f2 100644
--- a/src/3rdparty/webkit/WebCore/loader/ResourceLoader.cpp
+++ b/src/3rdparty/webkit/WebCore/loader/ResourceLoader.cpp
@@ -179,10 +179,16 @@ void ResourceLoader::addData(const char* data, int length, bool allAtOnce)
if (m_resourceData)
m_resourceData->append(data, length);
} else {
- if (!m_resourceData)
- m_resourceData = SharedBuffer::create(data, length);
- else
+ if (!m_resourceData) {
+ long long expectedContentLength = m_response.expectedContentLength();
+ // pre-allocate some capacity to avoid realloc/memcpy
+ if (expectedContentLength > 0 && expectedContentLength < 128*1024)
+ m_resourceData = SharedBuffer::create(data, length, expectedContentLength);
+ else
+ m_resourceData = SharedBuffer::create(data, length);
+ } else {
m_resourceData->append(data, length);
+ }
}
}
diff --git a/src/3rdparty/webkit/WebCore/platform/SharedBuffer.cpp b/src/3rdparty/webkit/WebCore/platform/SharedBuffer.cpp
index 4a0d0f3..9a77379 100644
--- a/src/3rdparty/webkit/WebCore/platform/SharedBuffer.cpp
+++ b/src/3rdparty/webkit/WebCore/platform/SharedBuffer.cpp
@@ -43,6 +43,12 @@ SharedBuffer::SharedBuffer(const unsigned char* data, int size)
{
m_buffer.append(data, size);
}
+
+SharedBuffer::SharedBuffer(const char* data, int size, int capacity)
+{
+ m_buffer.reserveCapacity(capacity);
+ m_buffer.append(data, size);
+}
SharedBuffer::~SharedBuffer()
{
diff --git a/src/3rdparty/webkit/WebCore/platform/SharedBuffer.h b/src/3rdparty/webkit/WebCore/platform/SharedBuffer.h
index 3404a0c..cbfeda8 100644
--- a/src/3rdparty/webkit/WebCore/platform/SharedBuffer.h
+++ b/src/3rdparty/webkit/WebCore/platform/SharedBuffer.h
@@ -52,6 +52,7 @@ class SharedBuffer : public RefCounted<SharedBuffer> {
public:
static PassRefPtr<SharedBuffer> create() { return adoptRef(new SharedBuffer); }
static PassRefPtr<SharedBuffer> create(const char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
+ static PassRefPtr<SharedBuffer> create(const char* c, int i, int capacity) { return adoptRef(new SharedBuffer(c, i, capacity)); }
static PassRefPtr<SharedBuffer> create(const unsigned char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
static PassRefPtr<SharedBuffer> createWithContentsOfFile(const String& filePath);
@@ -95,6 +96,7 @@ private:
SharedBuffer();
SharedBuffer(const char*, int);
SharedBuffer(const unsigned char*, int);
+ SharedBuffer(const char*, int, int);
void clearPlatformData();
void maybeTransferPlatformData();
--
1.6.2.1