Repository: sharkdp/bat
File: src/assets.rs (Rust)

Code before:
pub(crate) struct MinimalSyntaxes {
    /// Lookup the index into `serialized_syntax_sets` of a [SyntaxSet] by the
    /// name of any [SyntaxReference] inside the [SyntaxSet]
    /// (We will later add `by_extension`, `by_first_line`, etc.)
    pub(crate) by_name: HashMap<String, usize>,

    /// Serialized [SyntaxSet]s. Wether or not this data is compressed is
    /// decided by [COMPRESS_SERIALIZED_MINIMAL_SYNTAXES]
    pub(crate) serialized_syntax_sets: Vec<Vec<u8>>,
}

// Compress for size of ~700 kB instead of ~4600 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_SYNTAXES: bool = true;

// Compress for size of ~20 kB instead of ~200 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_THEMES: bool = true;

// Compress for size of ~400 kB instead of ~2100 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_SERIALIZED_MINIMAL_SYNTAXES: bool = true;

// Wether or not to compress the serialized form of [MinimalSyntaxes]. Shall
// always be `false`, because the data in
// [MinimalSyntaxes.serialized_syntax_sets] has already been compressed
// (assuming [COMPRESS_SERIALIZED_MINIMAL_SYNTAXES] is `true`). The "outer" data
// structures like `by_name` are tiny. If we compress, deserialization can't do
// efficient byte-by-byte copy of `serialized_syntax_sets`.
pub(crate) const COMPRESS_MINIMAL_SYNTAXES: bool = false;

const IGNORED_SUFFIXES: [&str; 13] = [
    // Editor etc backups
    "~",
    ".bak",
    ".old",
    ".orig",
    // Debian and derivatives apt/dpkg/ucf backups
    ".dpkg-dist",
    ".dpkg-old",
    ".ucf-dist",
    ".ucf-new",
    ".ucf-old",
    // Red Hat and derivatives rpm backups
    ".rpmnew",
    ".rpmorig",
    ".rpmsave",
    // Build system input/template files
    ".in",
];

impl HighlightingAssets {
    fn new(
        serialized_syntax_set: SerializedSyntaxSet,

Review comment (suggestion):
Okay. So this constant `COMPRESS_MINIMAL_SYNTAXES` is only here because we need to pass a `compressed` argument to the `asset_from_*` functions, and we don't want it to be just a plain "magic number" `false`. Correct?

If there is some form of restriction that is should be `false` if `COMPRESS_SERIALIZED_MINIMAL_SYNTAXES` is `true`, maybe we should add a [static assertion](https://docs.rs/static_assertions/1.1.0/static_assertions/macro.const_assert.html) for that? Something like
```rust
const_assert!(COMPRESS_MINIMAL_SYNTAXES ^ COMPRESS_SERIALIZED_MINIMAL_SYNTAXES);
```

(Not sure if it's worth adding a dependency just for that)

Code after:
pub(crate) struct MinimalSyntaxes {
    /// Lookup the index into `serialized_syntax_sets` of a [SyntaxSet] by the
    /// name of any [SyntaxReference] inside the [SyntaxSet]
    /// (We will later add `by_extension`, `by_first_line`, etc.)
    pub(crate) by_name: HashMap<String, usize>,

    /// Serialized [SyntaxSet]s. Whether or not this data is compressed is
    /// decided by [COMPRESS_SERIALIZED_MINIMAL_SYNTAXES]
    pub(crate) serialized_syntax_sets: Vec<Vec<u8>>,
}

// Compress for size of ~700 kB instead of ~4600 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_SYNTAXES: bool = true;

// Compress for size of ~20 kB instead of ~200 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_THEMES: bool = true;

// Compress for size of ~400 kB instead of ~2100 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_SERIALIZED_MINIMAL_SYNTAXES: bool = true;

// Whether or not to compress the serialized form of [MinimalSyntaxes]. Shall
// always be `false`, because the data in
// [MinimalSyntaxes.serialized_syntax_sets] has already been compressed
// (assuming [COMPRESS_SERIALIZED_MINIMAL_SYNTAXES] is `true`). The "outer" data
// structures like `by_name` are tiny. If we compress, deserialization can't do
// efficient byte-by-byte copy of `serialized_syntax_sets`.
pub(crate) const COMPRESS_MINIMAL_SYNTAXES: bool = false;

const IGNORED_SUFFIXES: [&str; 13] = [
    // Editor etc backups
    "~",
    ".bak",
    ".old",
    ".orig",
    // Debian and derivatives apt/dpkg/ucf backups
    ".dpkg-dist",
    ".dpkg-old",
    ".ucf-dist",
    ".ucf-new",
    ".ucf-old",
    // Red Hat and derivatives rpm backups
    ".rpmnew",
    ".rpmorig",
    ".rpmsave",
    // Build system input/template files
    ".in",
];

impl HighlightingAssets {
    fn new(
        serialized_syntax_set: SerializedSyntaxSet,