Преглед изворни кода

track: Use a linear map to store files by format.

Paul Lietar пре 9 година
родитељ
комит
ed14c3469b
5 измењених фајлова са 13 додато и 4 уклоњено
  1. 6 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 1 0
      src/lib.rs
  4. 3 2
      src/metadata.rs
  5. 2 2
      src/player.rs

+ 6 - 0
Cargo.lock

@@ -14,6 +14,7 @@ dependencies = [
  "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)",
  "librespot-protocol 0.1.0",
+ "linear-map 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -275,6 +276,11 @@ dependencies = [
  "pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "linear-map"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "lmdb-rs"
 version = "0.7.0"

+ 1 - 0
Cargo.toml

@@ -23,6 +23,7 @@ getopts         = "~0.2.14"
 hyper           = { version = "0.9.1", default-features = false }
 #json_macros     = "~0.3.0"
 lazy_static     = "~0.2.0"
+linear-map      = "1.0"
 lmdb-rs         = "0.7.0"
 num             = "~0.1.30"
 protobuf        = "~1.0.15"

+ 1 - 0
src/lib.rs

@@ -16,6 +16,7 @@ extern crate crypto;
 extern crate eventual;
 extern crate getopts;
 extern crate hyper;
+extern crate linear_map;
 extern crate lmdb_rs;
 extern crate num;
 extern crate protobuf;

+ 3 - 2
src/metadata.rs

@@ -1,4 +1,5 @@
 use eventual::{Async, Future};
+use linear_map::LinearMap;
 use protobuf;
 
 use protocol;
@@ -37,7 +38,7 @@ pub struct Track {
     pub name: String,
     pub album: SpotifyId,
     pub artists: Vec<SpotifyId>,
-    pub files: Vec<(FileId, FileFormat)>,
+    pub files: LinearMap<FileFormat, FileId>,
     pub alternatives: Vec<SpotifyId>,
     pub available: bool,
 }
@@ -85,7 +86,7 @@ impl MetadataTrait for Track {
                        .map(|file| {
                            let mut dst = [0u8; 20];
                            dst.clone_from_slice(&file.get_file_id());
-                           (FileId(dst), file.get_format())
+                           (file.get_format(), FileId(dst))
                        })
                        .collect();
 

+ 2 - 2
src/player.rs

@@ -196,8 +196,8 @@ fn load_track(session: &Session, track_id: SpotifyId) -> Option<vorbis::Decoder<
 
 
 
-    let file_id = match track.files.iter().find(|&&(_, f)| f == format) {
-        Some(&(file_id, _)) => file_id,
+    let file_id = match track.files.get(&format) {
+        Some(&file_id) => file_id,
         None => {
             warn!("Track \"{}\" is not available in format {:?}", track.name, format);
             return None;