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

Improvement suggestion for Base.Sublist #16

Open
GoogleCodeExporter opened this issue Feb 7, 2016 · 1 comment
Open

Improvement suggestion for Base.Sublist #16

GoogleCodeExporter opened this issue Feb 7, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

I think I see an improvement needed in method base.sublist around ln 109 in 
Base.cs 

Seeing as though 'sublist' is called to create a sublist of things like top 
tags, for example if Last.Fm returns 0 tags for an artist - an Out Of Range 
Exception occurs at 'original[i]' as the original list is empty . I have added 
a length check that returns an empty array if needed:

internal T[] sublist<T> (T[] original, int length)
{
   List<T> list = new List<T>();

   // IMPROVEMENT - if original is empty - return 
   if (original.Length < 1) return list.ToArray();

   for(int i=0; i<length; i++)
   list.Add(original[i]);

   return list.ToArray();
}

This will occur when calling:
:Artist.GetTopTags(int limit)
:Track.GetTopFans(int limit)
:Track.GetTopTags(int limit)
:Album.GetTopTags(int limit)
:User.GetTopTags(int limit)
:User.GetNeighbours(int limit)
:User.GetFriends(int limit)

Original issue reported on code.google.com by sa...@trackn.fm on 19 Nov 2013 at 7:55

@GoogleCodeExporter
Copy link
Author

This will occur when calling those methods - only when Last.Fm returns an empty 
list.

Original comment by sa...@trackn.fm on 19 Nov 2013 at 7:56

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

No branches or pull requests

1 participant