Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: LinkBehaviour to AddTo #106

Merged
merged 2 commits into from
Mar 17, 2024
Merged

Add: LinkBehaviour to AddTo #106

merged 2 commits into from
Mar 17, 2024

Conversation

AnnulusGames
Copy link
Owner

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);
}

@AnnulusGames
Copy link
Owner Author

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.

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

#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.

2 participants