Closed Bug 328196 Opened 18 years ago Closed 18 years ago

nsDiskCacheDevice: Memory and codesize optimisations

Categories

(Core :: Networking: Cache, defect)

defect
Not set
minor

Tracking

()

VERIFIED FIXED

People

(Reporter: alfredkayser, Assigned: alfredkayser)

References

Details

Attachments

(1 file)

Some minor optimisations for nsDiskCacheDevice, including two malloc removals: 
One in the VisitRecord, and one for the mCacheMap member.

In  nsDiskCacheEvictor::VisitRecord(nsDiskCacheRecord *  mapRecord)
-        // XXX FIXME compare clientID's without malloc
This can be easily fixed, by doing a direct check of the clientID in
the diskEntry, as follows:
+        // Compare clientID's without malloc
+        if ((diskEntry->mKeySize <= mClientIDSize) ||
+            (diskEntry->mKeyStart[mClientIDSize] != ':') ||
+            (memcmp(diskEntry->mKeyStart, mClientID, mClientIDSize) != 0)) {

* Make mCacheMap a static member of nsDiskCacheDevice, so that we can remove the 'new nsDiskCacheMap' and the checking for null pointer, and that all references to mCacheMap stuff goes directly from nsDiskCacheMap.
-    nsDiskCacheMap *        mCacheMap;
+    nsDiskCacheMap          mCacheMap;
-    mCacheMap = new nsDiskCacheMap;
-    if (!mCacheMap)
-        return NS_ERROR_OUT_OF_MEMORY;

Also DoomRecord in nsDiskCacheMap can be removed by calling DeleteRecord directly.
Also DeleteRecordAndStorage is only called from one place, and can be replaced by calling DeleteRecord and DeleteStorage directly from that place.
The 'InitializeCacheDirectory()' is only called from one place (OpenDiskCache), and the logic of OpenDiskCache is easier to follow if the logic from 'InitializeCacheDirectory()' is placed inline (which is 'create directory, open cache map at that directory').

From both visitors, the mDevice member can be removed, and
from the EntryInfoVisitor, the mResult member is not used.

Also made the following private:
-    PRBool                  Initialized() { return mInitialized; }
-    nsresult                Shutdown_Private(PRBool flush);
Assignee: darin → alfredkayser
Status: NEW → ASSIGNED
Attachment #212739 - Flags: review?(darin)
Any interest in fixing bug 321456 along with this one?
Codesize savings is about 1.5K:
OLD:    243.108 nkcache_s.lib
NEW:    241.490 nkcache_s.lib
It is better keep bug 321456 separate, but I will look into that as well.
Comment on attachment 212739 [details] [diff] [review]
First version, incl. all described optimalizations

r=darin, sorry for the long delay.
Attachment #212739 - Flags: review?(darin) → review+
fixed-on-trunk

heh.. i was thinking of a different bug when i made that last comment ;-)
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
See also bug 405407 for more memory & disk optimisations...
Blocks: 405407
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: