Skip to content

Conversation

@nuskey8
Copy link
Member

@nuskey8 nuskey8 commented Mar 17, 2024

No description provided.

@akeit0
Copy link
Contributor

akeit0 commented Mar 17, 2024

This seems good.
However, there is one improvement, it would be better if the initialization of the List is lazy.

struct LazyFastListCore<T>{
    public static int InitialCapacity=8;
    T[] array;
    int tailIndex;
    void AllocateIfNeeded(){
         if(array==null)array=new T[InitialCapacity];
    }

     public void Add(T element)
     {
         AllocateIfNeeded();
          if (array.Length == tailIndex)
          {
              Array.Resize(ref array, tailIndex * 2);
          }

          array[tailIndex] = element;
          tailIndex++;
      }

     public readonly Span<T> AsSpan() => array==null?default:array.AsSpan(0, tailIndex);
}

@nuskey8
Copy link
Member Author

nuskey8 commented Mar 17, 2024

Yes, I see that. If so, it would be better to delay the FastListCore array generation in the first place. Once this PR is merged, another PR will take care of it immediately.

@nuskey8 nuskey8 merged commit b222616 into main Mar 17, 2024
@nuskey8 nuskey8 deleted the feature-addto-behaviour branch March 17, 2024 10:24
@nuskey8
Copy link
Member Author

nuskey8 commented Mar 17, 2024

#107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants