Minify macros by introducing store-level operation macro
This commit is contained in:
parent
d91243d4b4
commit
3a90077777
3 changed files with 60 additions and 66 deletions
|
@ -88,16 +88,9 @@ impl_verified_object!(RFileLockEntry);
|
|||
#[macro_export]
|
||||
macro_rules! call_on_fle_from_store {
|
||||
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{
|
||||
use cache::RUBY_STORE_CACHE;
|
||||
|
||||
let arc = RUBY_STORE_CACHE.clone();
|
||||
{
|
||||
let lock = arc.lock();
|
||||
match lock {
|
||||
Ok(mut hm) => {
|
||||
let handle = $itself.get_data(&*$wrapper);
|
||||
match hm.get(handle.store_handle()) {
|
||||
Some(store) => {
|
||||
let store_handle = handle.store_handle();
|
||||
call_on_store_by_handle!(store_handle -> store -> {
|
||||
match store.get(handle.fle_handle().clone()) {
|
||||
Ok(Some(mut $name)) => {
|
||||
$operation
|
||||
|
@ -111,32 +104,12 @@ macro_rules! call_on_fle_from_store {
|
|||
NilClass::new().to_any_object()
|
||||
},
|
||||
}
|
||||
},
|
||||
None => {
|
||||
VM::raise(Class::from_existing("RuntimeError"),
|
||||
"Tried to operate on non-existing object");
|
||||
NilClass::new().to_any_object()
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
||||
NilClass::new().to_any_object()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}};
|
||||
($itself:ident ($wrapper:ident) -> $name:ident -> $operation: block on fail return $ex:expr) => {{
|
||||
use cache::RUBY_STORE_CACHE;
|
||||
|
||||
let arc = RUBY_STORE_CACHE.clone();
|
||||
{
|
||||
let lock = arc.lock();
|
||||
match lock {
|
||||
Ok(mut hm) => {
|
||||
let handle = $itself.get_data(&*$wrapper);
|
||||
match hm.get(handle.store_handle()) {
|
||||
Some(store) => {
|
||||
let store_handle = handle.store_handle();
|
||||
call_on_store_by_handle!(store_handle -> store -> {
|
||||
match store.get(handle.fle_handle().clone()) {
|
||||
Ok(Some(mut $name)) => {
|
||||
$operation
|
||||
|
@ -150,20 +123,7 @@ macro_rules! call_on_fle_from_store {
|
|||
$ex
|
||||
},
|
||||
}
|
||||
},
|
||||
None => {
|
||||
VM::raise(Class::from_existing("RuntimeError"),
|
||||
"Tried to operate on non-existing object");
|
||||
NilClass::new().to_any_object()
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
||||
NilClass::new().to_any_object()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ extern crate libimagrt;
|
|||
#[macro_use] extern crate libimagutil;
|
||||
|
||||
#[macro_use] mod util;
|
||||
#[macro_use] pub mod store;
|
||||
mod cache;
|
||||
|
||||
pub mod entry;
|
||||
pub mod imag;
|
||||
pub mod ruby_utils;
|
||||
pub mod store;
|
||||
pub mod storeid;
|
||||
pub mod toml_utils;
|
||||
|
||||
|
|
|
@ -39,6 +39,40 @@ impl_wrap!(Store, STORE_WRAPPER);
|
|||
impl_unwrap!(RStore, Store, STORE_WRAPPER);
|
||||
impl_verified_object!(RStore);
|
||||
|
||||
macro_rules! call_on_store_by_handle {
|
||||
($store_handle:ident -> $name:ident -> $operation:block) => {{
|
||||
use cache::RUBY_STORE_CACHE;
|
||||
|
||||
let arc = RUBY_STORE_CACHE.clone();
|
||||
{
|
||||
let lock = arc.lock();
|
||||
match lock {
|
||||
Ok(mut hm) => {
|
||||
match hm.get($store_handle) {
|
||||
Some($name) => { $operation },
|
||||
None => {
|
||||
VM::raise(Class::from_existing("RuntimeError"),
|
||||
"Tried to operate on non-existing object");
|
||||
NilClass::new().to_any_object()
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
||||
NilClass::new().to_any_object()
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
macro_rules! call_on_store {
|
||||
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{
|
||||
let handle = $itself.get_data(&*$wrapper).store_handle();
|
||||
call_on_store_by_handle!(handle -> $name -> $operation)
|
||||
}};
|
||||
}
|
||||
|
||||
methods!(
|
||||
RStore,
|
||||
itself,
|
||||
|
|
Loading…
Reference in a new issue