Example #1
0
 private static void ClearEntry(DeltaBaseCache.Slot e)
 {
     openByteCount -= e.sz;
     e.provider     = null;
     e.data         = DEAD;
     e.sz           = 0;
 }
 internal virtual void Store(PackFile pack, long position, byte[] data, int objectType
                             )
 {
     if (data.Length > maxByteCount)
     {
         return;
     }
     // Too large to cache.
     DeltaBaseCache.Slot e = cache[Hash(position)];
     if (e == null)
     {
         e = new DeltaBaseCache.Slot();
         cache[Hash(position)] = e;
     }
     else
     {
         ClearEntry(e);
     }
     openByteCount += data.Length;
     ReleaseMemory();
     e.provider = pack;
     e.position = position;
     e.sz       = data.Length;
     e.data     = new SoftReference <DeltaBaseCache.Entry>(new DeltaBaseCache.Entry(data, objectType
                                                                                    ));
     MoveToHead(e);
 }
		static DeltaBaseCache()
		{
			DEAD = new SoftReference<DeltaBaseCache.Entry>(null);
			maxByteCount = new WindowCacheConfig().GetDeltaBaseCacheLimit();
			cache = new DeltaBaseCache.Slot[CACHE_SZ];
			for (int i = 0; i < CACHE_SZ; i++)
			{
				cache[i] = new DeltaBaseCache.Slot();
			}
		}
Example #4
0
 static DeltaBaseCache()
 {
     DEAD         = new SoftReference <DeltaBaseCache.Entry>(null);
     maxByteCount = new WindowCacheConfig().GetDeltaBaseCacheLimit();
     cache        = new DeltaBaseCache.Slot[CACHE_SZ];
     for (int i = 0; i < CACHE_SZ; i++)
     {
         cache[i] = new DeltaBaseCache.Slot();
     }
 }
Example #5
0
 private static void Unlink(DeltaBaseCache.Slot e)
 {
     DeltaBaseCache.Slot prev = e.lruPrev;
     DeltaBaseCache.Slot next = e.lruNext;
     if (prev != null)
     {
         prev.lruNext = next;
     }
     if (next != null)
     {
         next.lruPrev = prev;
     }
 }
Example #6
0
 private static void MoveToHead(DeltaBaseCache.Slot e)
 {
     Unlink(e);
     e.lruPrev = null;
     e.lruNext = lruHead;
     if (lruHead != null)
     {
         lruHead.lruPrev = e;
     }
     else
     {
         lruTail = e;
     }
     lruHead = e;
 }
Example #7
0
 internal static DeltaBaseCache.Entry Get(PackFile pack, long position)
 {
     lock (typeof(DeltaBaseCache))
     {
         DeltaBaseCache.Slot e = cache[Hash(position)];
         if (e.provider == pack && e.position == position)
         {
             DeltaBaseCache.Entry buf = e.data.Get();
             if (buf != null)
             {
                 MoveToHead(e);
                 return(buf);
             }
         }
         return(null);
     }
 }
 internal virtual DeltaBaseCache.Entry Get(PackFile pack, long position)
 {
     DeltaBaseCache.Slot e = cache[Hash(position)];
     if (e == null)
     {
         return(null);
     }
     if (e.provider == pack && e.position == position)
     {
         DeltaBaseCache.Entry buf = e.data.Get();
         if (buf != null)
         {
             MoveToHead(e);
             return(buf);
         }
     }
     return(null);
 }
Example #9
0
 private static void ReleaseMemory()
 {
     while (openByteCount > maxByteCount && lruTail != null)
     {
         DeltaBaseCache.Slot currOldest = lruTail;
         DeltaBaseCache.Slot nextOldest = currOldest.lruPrev;
         ClearEntry(currOldest);
         currOldest.lruPrev = null;
         currOldest.lruNext = null;
         if (nextOldest == null)
         {
             lruHead = null;
         }
         else
         {
             nextOldest.lruNext = null;
         }
         lruTail = nextOldest;
     }
 }
Example #10
0
 internal static void Store(PackFile pack, long position, byte[] data, int objectType
                            )
 {
     lock (typeof(DeltaBaseCache))
     {
         if (data.Length > maxByteCount)
         {
             return;
         }
         // Too large to cache.
         DeltaBaseCache.Slot e = cache[Hash(position)];
         ClearEntry(e);
         openByteCount += data.Length;
         ReleaseMemory();
         e.provider = pack;
         e.position = position;
         e.sz       = data.Length;
         e.data     = new SoftReference <DeltaBaseCache.Entry>(new DeltaBaseCache.Entry(data, objectType
                                                                                        ));
         MoveToHead(e);
     }
 }
Example #11
0
		private static void MoveToHead(DeltaBaseCache.Slot e)
		{
			Unlink(e);
			e.lruPrev = null;
			e.lruNext = lruHead;
			if (lruHead != null)
			{
				lruHead.lruPrev = e;
			}
			else
			{
				lruTail = e;
			}
			lruHead = e;
		}
Example #12
0
		private static void ReleaseMemory()
		{
			while (openByteCount > maxByteCount && lruTail != null)
			{
				DeltaBaseCache.Slot currOldest = lruTail;
				DeltaBaseCache.Slot nextOldest = currOldest.lruPrev;
				ClearEntry(currOldest);
				currOldest.lruPrev = null;
				currOldest.lruNext = null;
				if (nextOldest == null)
				{
					lruHead = null;
				}
				else
				{
					nextOldest.lruNext = null;
				}
				lruTail = nextOldest;
			}
		}
Example #13
0
		internal virtual void Store(PackFile pack, long position, byte[] data, int objectType
			)
		{
			if (data.Length > maxByteCount)
			{
				return;
			}
			// Too large to cache.
			DeltaBaseCache.Slot e = cache[Hash(position)];
			if (e == null)
			{
				e = new DeltaBaseCache.Slot();
				cache[Hash(position)] = e;
			}
			else
			{
				ClearEntry(e);
			}
			openByteCount += data.Length;
			ReleaseMemory();
			e.provider = pack;
			e.position = position;
			e.sz = data.Length;
			e.data = new SoftReference<DeltaBaseCache.Entry>(new DeltaBaseCache.Entry(data, objectType
				));
			MoveToHead(e);
		}