コード例 #1
0
ファイル: WListBase.cs プロジェクト: lydonchandra/Loyc
 /// <summary>Returns this list as an RVList; if this is a FWList, the order
 /// of the elements is reversed at the same time.</summary>
 /// <remarks>This operation marks the items of the FWList or RWList as
 /// immutable. You can still modify the list afterward, but some or all
 /// of the list may have to be copied.</remarks>
 protected RVList <T> ToRVList()
 {
     if (IsOwner)
     {
         return(VListBlock <T> .EnsureImmutable(Block, LocalCount).ToRVList());
     }
     else
     {
         return(InternalVList.ToRVList());
     }
 }
コード例 #2
0
ファイル: WListBase.cs プロジェクト: lydonchandra/Loyc
        protected void InsertRangeAtDff(int distanceFromFront, IList <T> items, bool isRWList)
        {
            int count = items.Count;             // (may throw NullReferenceException)

            if ((uint)distanceFromFront > (uint)Count)
            {
                throw new IndexOutOfRangeException();
            }

            if (items == this)
            {
                // Inserting a copy of the list into itself requires some care...
                if (distanceFromFront == 0)
                {
                    // this sublist won't change during the insert
                    if (isRWList)
                    {
                        items = InternalVList.ToRVList();
                    }
                    else
                    {
                        items = InternalVList;
                    }
                }
                else
                {
                    items = ToFVList();                         // get an immutable version
                }
            }
            VListBlock <T> .EnsureMutable(this, distanceFromFront);

            VListBlock <T> .MuAddEmpty(this, count);

            VListBlock <T> .MuMove(this, count, 0, distanceFromFront);

            if (isRWList)
            {
                // Add items in forward order for RWList
                for (int i = 0; i < count; i++)
                {
                    SetAtDff(distanceFromFront + count - 1 - i, items[i]);
                }
            }
            else
            {
                // Add items in reverse order for FWList
                for (int i = 0; i < count; i++)
                {
                    SetAtDff(distanceFromFront + i, items[i]);
                }
            }
        }