Skip to content

Commit

Permalink
release: 3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Jun 18, 2024
2 parents 494208d + 906bf18 commit a571c4a
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 293 deletions.
6 changes: 3 additions & 3 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Project Dependencies
Package: flaca
Version: 3.1.1
Generated: 2024-06-13 17:53:19 UTC
Version: 3.1.2
Generated: 2024-06-18 04:53:29 UTC

| Package | Version | Author(s) | License |
| ---- | ---- | ---- | ---- |
Expand All @@ -19,7 +19,7 @@
| [dowser](https://github.com/Blobfolio/dowser) | 0.9.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [equivalent](https://github.com/cuviper/equivalent) | 1.0.1 | | Apache-2.0 or MIT |
| [fastrand](https://github.com/smol-rs/fastrand) | 2.1.0 | [Stjepan Glavina](mailto:stjepang@gmail.com) | Apache-2.0 or MIT |
| flapfli | 3.1.1 | [Josh Stoik](mailto:josh@blobfolio.com) | WTFPL |
| flapfli | 3.1.2 | [Josh Stoik](mailto:josh@blobfolio.com) | WTFPL |
| [funty](https://github.com/myrrlyn/funty) | 2.0.0 | [myrrlyn](mailto:self@myrrlyn.dev) | MIT |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.13.6 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [hashbrown](https://github.com/rust-lang/hashbrown) | 0.14.5 | [Amanieu d'Antras](mailto:amanieu@gmail.com) | Apache-2.0 or MIT |
Expand Down
2 changes: 1 addition & 1 deletion flaca/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flaca"
version = "3.1.1"
version = "3.1.2"
license = "WTFPL"
authors = ["Josh Stoik <josh@blobfolio.com>"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion flapfli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flapfli"
version = "3.1.1"
version = "3.1.2"
license = "WTFPL"
authors = ["Josh Stoik <josh@blobfolio.com>"]
edition = "2021"
Expand Down
76 changes: 40 additions & 36 deletions flapfli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ fn build_symbols() {
use std::fmt::Write;

let mut out = format!(
"{}{}{}{}{}",
"{}{}{}{}{}{}",
NumEnum::new(0..19_u8, "Whackadoodle Deflate Indices.", "DeflateSym")
.with_debug()
.with_eq(),
.with_eq()
.with_iter(),
NumEnum::new(0..32_u16, "Distance Symbols.", "Dsym"),
NumEnum::new(0..259_u16, "Lit/Lengths.", "LitLen").with_eq(),
NumEnum::new(0..259_u16, "Lit/Lengths.", "LitLen").with_eq().with_iter(),
NumEnum::new(0..286_u16, "Lit/Length Symbols.", "Lsym"),
NumEnum::new(0..9_u16, "Block Splitting Indices.", "SplitPIdx").with_iter(),
NumEnum::new(0..15_u8, "Block Split Length.", "SplitLen").with_eq(),
);

out.push_str(r"/// # Distance Symbols by Distance
Expand Down Expand Up @@ -242,15 +244,15 @@ fn write(path: &Path, data: &[u8]) {
/// We have a lot of custom numeric types that cover a range of numbers; this
/// struct ensures we generate their code consistently.
struct NumEnum<T: Copy + fmt::Display>
where Range<T>: Iterator<Item=T> + ExactSizeIterator {
where Range<T>: ExactSizeIterator<Item=T> {
rng: Range<T>,
title: &'static str,
name: &'static str,
flags: u8,
}

impl<T: Copy + fmt::Display> NumEnum<T>
where Range<T>: Iterator<Item=T> + ExactSizeIterator {
where Range<T>: ExactSizeIterator<Item=T> {
const DERIVE_DEBUG: u8 = 0b0000_0001;
const DERIVE_EQ: u8 = 0b0000_0010;
const DERIVE_ITER: u8 = 0b0000_0100;
Expand Down Expand Up @@ -286,7 +288,7 @@ where Range<T>: Iterator<Item=T> + ExactSizeIterator {
}

impl<T: Copy + fmt::Display> fmt::Display for NumEnum<T>
where Range<T>: Iterator<Item=T> + ExactSizeIterator {
where Range<T>: ExactSizeIterator<Item=T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Allow dead code.
writeln!(f, "#[allow(dead_code)]")?;
Expand Down Expand Up @@ -319,36 +321,38 @@ where Range<T>: Iterator<Item=T> + ExactSizeIterator {

// Symbol iterator?
if Self::DERIVE_ITER == self.flags & Self::DERIVE_ITER {
// The iterator struct.
writeln!(f, "/// # `{}` Iterator.", self.name)?;
writeln!(f, "pub(crate) struct {}Iter({kind});", self.name)?;

// The Iterator impl.
writeln!(f, "impl Iterator for {}Iter {{", self.name)?;
writeln!(f, "\ttype Item = {};", self.name)?;
writeln!(f, "\tfn next(&mut self) -> Option<Self::Item> {{")?;
writeln!(f, "\t\tlet old = self.0;")?;
writeln!(f, "\t\tif old < {} {{", self.rng.end)?;
writeln!(f, "\t\t\tself.0 += 1;")?;
writeln!(f, "\t\t\t#[allow(unsafe_code)]")?;
writeln!(f, "\t\t\tSome(unsafe {{ std::mem::transmute::<{kind}, {}>(old) }})", self.name)?;
writeln!(f, "\t\t}} else {{ None }}")?;
writeln!(f, "\t}}")?;
writeln!(f, "}}")?;

// The ExactSizeIterator impl.
writeln!(f, "impl ExactSizeIterator for {}Iter {{", self.name)?;
writeln!(f, "\tfn len(&self) -> usize {{")?;
writeln!(f, "\t\tusize::from({}_{kind}.saturating_sub(self.0))", self.rng.end)?;
writeln!(f, "\t}}")?;
writeln!(f, "}}")?;

// Our SymbolIteration impl.
writeln!(f, "impl SymbolIteration for {} {{", self.name)?;
writeln!(f, "\tfn all() -> impl ExactSizeIterator<Item=Self> {{")?;
writeln!(f, "\t\t{}Iter({})", self.name, self.rng.start)?;
writeln!(f, "\t}}")?;
writeln!(f, "}}")?;
writeln!(
f,
"/// # `{name}` Iterator.
pub(crate) struct {name}Iter({kind});
impl Iterator for {name}Iter {{
type Item = {name};
fn next(&mut self) -> Option<Self::Item> {{
let old = self.0;
if old < {end} {{
self.0 += 1;
#[allow(unsafe_code)]
Some(unsafe {{ std::mem::transmute::<{kind}, {name}>(old) }})
}}
else {{ None }}
}}
}}
impl ExactSizeIterator for {name}Iter {{
fn len(&self) -> usize {{
usize::from({end}_{kind}.saturating_sub(self.0))
}}
}}
impl SymbolIteration<{name}Iter> for {name} {{
fn all() -> {name}Iter {{ {name}Iter({start}) }}
}}
",
name=self.name,
end=self.rng.end,
start=self.rng.start,
)?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions flapfli/src/lodepng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub(crate) extern "C" fn flaca_png_deflate(

#[cfg(debug_assertions)] if let Err(e) = res { panic!("{e}"); }

// For non-debug purposes, just let lodepng know we failed when thre's
// an error so it can skip the rest of the processing.
// Errors shouldn't be possible, but if something happens to go wrong,
// return one so lodepng can abandon its efforts.
if res.is_err() { return 1; }

// Onward and upward!
Expand Down
Loading

0 comments on commit a571c4a

Please sign in to comment.