зеркало из https://github.com/mozilla/pjs.git
bug 144884 Necko buffer cache. r=rjc, sr=darin
This commit is contained in:
Родитель
6ebd2105e5
Коммит
6caddcaaa3
|
@ -65,6 +65,7 @@
|
|||
#include "nsITimelineService.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIRecyclingAllocator.h"
|
||||
|
||||
#define PORT_PREF_PREFIX "network.security.ports."
|
||||
#define PORT_PREF(x) PORT_PREF_PREFIX x
|
||||
|
@ -144,6 +145,9 @@ PRInt16 gBadPortList[] = {
|
|||
static const char kProfileChangeNetTeardownTopic[] = "profile-change-net-teardown";
|
||||
static const char kProfileChangeNetRestoreTopic[] = "profile-change-net-restore";
|
||||
|
||||
// Necko buffer cache
|
||||
nsIMemory* nsIOService::gBufferCache = nsnull;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsIOService::nsIOService()
|
||||
|
@ -151,6 +155,24 @@ nsIOService::nsIOService()
|
|||
mOfflineForProfileChange(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
// Get the allocator ready
|
||||
if (!gBufferCache)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIRecyclingAllocator> recyclingAllocator =
|
||||
do_CreateInstance(NS_RECYCLINGALLOCATOR_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
rv = recyclingAllocator->Init(NS_NECKO_BUFFER_CACHE_COUNT,
|
||||
NS_NECKO_15_MINS, "necko");
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIMemory> eyeMemory = do_QueryInterface(recyclingAllocator);
|
||||
gBufferCache = eyeMemory.get();
|
||||
NS_IF_ADDREF(gBufferCache);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -55,6 +55,8 @@
|
|||
#include "nsWeakReference.h"
|
||||
|
||||
#define NS_N(x) (sizeof(x)/sizeof(*x))
|
||||
#define NS_NECKO_BUFFER_CACHE_COUNT (24) // Max holdings: 24 * 4k = 96k
|
||||
#define NS_NECKO_15_MINS (15 * 60)
|
||||
|
||||
static const char *gScheme[] = {"chrome", "file", "http", "jar", "resource"};
|
||||
|
||||
|
@ -123,6 +125,11 @@ protected:
|
|||
nsCOMPtr<nsIURLParser> mDefaultURLParser;
|
||||
nsAutoVoidArray mURLParsers;
|
||||
nsVoidArray mRestrictedPortList;
|
||||
|
||||
public:
|
||||
// Necko buffer cache. Used for all default buffer sizes that necko
|
||||
// allocates.
|
||||
static nsIMemory *gBufferCache;
|
||||
};
|
||||
|
||||
#endif // nsIOService_h__
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "nsIPipe.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "prlog.h"
|
||||
#include "nsIOService.h"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
static PRLogModuleInfo *gStreamListenerProxyLog;
|
||||
|
@ -395,11 +396,15 @@ nsStreamListenerProxy::Init(nsIStreamListener *listener,
|
|||
// The segment size must not exceed the maximum
|
||||
bufferSegmentSize = PR_MIN(bufferMaxSize, bufferSegmentSize);
|
||||
|
||||
// Use the necko buffer cache for the default buffers
|
||||
nsIMemory *allocator = nsnull;
|
||||
if (bufferSegmentSize == DEFAULT_BUFFER_SEGMENT_SIZE)
|
||||
allocator = nsIOService::gBufferCache;
|
||||
nsresult rv = NS_NewPipe(getter_AddRefs(mPipeIn),
|
||||
getter_AddRefs(mPipeOut),
|
||||
bufferSegmentSize,
|
||||
bufferMaxSize,
|
||||
PR_TRUE, PR_TRUE);
|
||||
PR_TRUE, PR_TRUE, allocator);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRequestObserver> observer = do_QueryInterface(listener);
|
||||
|
|
|
@ -588,6 +588,9 @@ static void PR_CALLBACK nsNeckoShutdown(nsIModule *neckoModule)
|
|||
{
|
||||
// Release the url parser that the stdurl is holding.
|
||||
nsStandardURL::ShutdownGlobalObjects();
|
||||
|
||||
// Release buffer cache
|
||||
NS_IF_RELEASE(nsIOService::gBufferCache);
|
||||
}
|
||||
|
||||
static const nsModuleComponentInfo gNetModuleInfo[] = {
|
||||
|
|
Загрузка…
Ссылка в новой задаче