Reduce the object size of the big match in get_tag_info().

This commit is contained in:
KAMADA Ken'ichi 2016-12-14 22:02:55 +09:00
parent 5cb98a8f1b
commit e894654d68
1 changed files with 18 additions and 8 deletions

View File

@ -98,11 +98,6 @@ pub enum Context {
Interop, // 0th/1st IFD -- Exif IFD -- Interoperability IFD
}
struct TagInfo {
name: &'static str,
desc: &'static str,
}
macro_rules! generate_well_known_tag_constants {
(
$( |$ctx:path| $(
@ -117,10 +112,25 @@ macro_rules! generate_well_known_tag_constants {
pub const $name: Tag = Tag($ctx, $num);
)+)+
fn get_tag_info(tag: &Tag) -> Option<TagInfo> {
// Use a separate module to avoid name conflicts between
// const Tag and static TagInfo.
mod tag_info {
pub struct TagInfo {
pub name: &'static str,
pub desc: &'static str,
}
$($(
#[allow(non_upper_case_globals)]
pub static $name: TagInfo = TagInfo {
name: stringify!($name), desc: $desc };
)+)+
}
fn get_tag_info(tag: &Tag) -> Option<&tag_info::TagInfo> {
match *tag {
$($( self::$name => Some(TagInfo {
name: stringify!($name), desc: $desc }),
$($(
self::$name => Some(&tag_info::$name),
)+)+
_ => None,
}