[banshee] Lastfm: refactor to optimize the check for queue's emptiness by using Linq
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Lastfm: refactor to optimize the check for queue's emptiness by using Linq
- Date: Sat, 16 Mar 2013 23:07:39 +0000 (UTC)
commit 5d46d00113bd9ab0d754b6ec761bb3d9117571b9
Author: Andres G. Aragoneses <knocte gmail com>
Date: Sat Mar 16 21:52:00 2013 +0000
Lastfm: refactor to optimize the check for queue's emptiness by using Linq
No change of behaviour in this commit.
.../Banshee.Lastfm.Audioscrobbler/Queue.cs | 14 ++++++++++++++
src/Libraries/Lastfm/Lastfm.csproj | 1 +
.../Lastfm/Lastfm/AudioscrobblerConnection.cs | 5 +++--
src/Libraries/Lastfm/Lastfm/IQueue.cs | 2 +-
4 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs
b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs
index fe1972d..5a41071 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs
@@ -164,6 +164,20 @@ namespace Banshee.Lastfm.Audioscrobbler
Load ();
}
+ #region IEnumerable implementation
+
+ IEnumerator<IQueuedTrack> IEnumerable<IQueuedTrack>.GetEnumerator ()
+ {
+ return queue.GetEnumerator ();
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return queue.GetEnumerator ();
+ }
+
+ #endregion
+
private void MigrateQueueFile ()
{
string old_xml_dir_path = Path.Combine (Hyena.Paths.ExtensionCacheRoot, "last.fm");
diff --git a/src/Libraries/Lastfm/Lastfm.csproj b/src/Libraries/Lastfm/Lastfm.csproj
index 25cb353..5e1d8f9 100644
--- a/src/Libraries/Lastfm/Lastfm.csproj
+++ b/src/Libraries/Lastfm/Lastfm.csproj
@@ -50,6 +50,7 @@
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\..\..\bin\bin\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
+ <Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mono.Media\Mono.Media.csproj">
diff --git a/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
b/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
index 3e685a6..230199c 100644
--- a/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
+++ b/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
@@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.IO;
using System.Net;
using System.Text;
@@ -168,7 +169,7 @@ namespace Lastfm
// and address changes in our engine state
switch (state) {
case State.Idle:
- if (queue.Count > 0) {
+ if (queue.Any ()) {
state = State.NeedTransmit;
} else if (current_now_playing_request != null) {
// Now playing info needs to be sent
@@ -322,7 +323,7 @@ namespace Lastfm
}
// if there are still valid tracks in the queue then retransmit on the next interval
- state = queue.Count > 0 ? State.NeedTransmit : State.Idle;
+ state = queue.Any () ? State.NeedTransmit : State.Idle;
}
private void LogIfIgnored (JsonObject scrobbled_track)
diff --git a/src/Libraries/Lastfm/Lastfm/IQueue.cs b/src/Libraries/Lastfm/Lastfm/IQueue.cs
index 6eb4015..4548a5c 100644
--- a/src/Libraries/Lastfm/Lastfm/IQueue.cs
+++ b/src/Libraries/Lastfm/Lastfm/IQueue.cs
@@ -45,7 +45,7 @@ namespace Lastfm
string TrackAuth { get; }
}
- public interface IQueue
+ public interface IQueue : IEnumerable<IQueuedTrack>
{
event EventHandler TrackAdded;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]