Пример #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);
 }
Пример #3
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();
			}
		}
Пример #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();
     }
 }
Пример #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;
     }
 }
Пример #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;
 }
Пример #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);
 }
Пример #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;
     }
 }
Пример #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);
     }
 }
Пример #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;
		}
Пример #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;
			}
		}
Пример #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);
		}