Skip to content

Commit

Permalink
Bump quick-xml to 0.37.0 and remove it from public APIs (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
RedPhoenixQ authored Nov 19, 2024
1 parent 54866ee commit cf4f325
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Remove `quick_xml::Error` from the public API. [#332](https://github.com/jonhoo/inferno/pull/332)

### Removed

## [0.11.21] - 2024-08-03
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ indexmap = { version = "2.0", optional = true }
itoa = "1"
log = "0.4"
num-format = { version = "0.4.3", default-features = false }
quick-xml = { version = "0.26", default-features = false }
quick-xml = { version = "0.37", default-features = false }
rgb = "0.8.13"
str_stack = "0.1"
clap = { version = "4.0.1", optional = true, features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'a> Opt {

const PALETTE_MAP_FILE: &str = "palette.map"; // default name for the palette map file

fn main() -> quick_xml::Result<()> {
fn main() -> io::Result<()> {
let opt = Opt::parse();

// Initialize logger
Expand Down Expand Up @@ -343,7 +343,7 @@ fn main() -> quick_xml::Result<()> {
)?;
}

save_consistent_palette_if_needed(&palette_map, PALETTE_MAP_FILE).map_err(quick_xml::Error::Io)
save_consistent_palette_if_needed(&palette_map, PALETTE_MAP_FILE)
}

fn fetch_consistent_palette_if_needed(
Expand Down
6 changes: 3 additions & 3 deletions src/flamegraph/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn flow<'a, LI, TI>(
pub(super) fn frames<'a, I>(
lines: I,
suppress_sort_check: bool,
) -> quick_xml::Result<(Vec<TimedFrame<'a>>, usize, usize, usize)>
) -> io::Result<(Vec<TimedFrame<'a>>, usize, usize, usize)>
where
I: IntoIterator<Item = &'a str>,
{
Expand All @@ -128,10 +128,10 @@ where
if !suppress_sort_check {
if let Some(prev_line) = prev_line {
if prev_line > line {
return Err(quick_xml::Error::Io(io::Error::new(
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"unsorted input lines detected",
)));
));
}
}
}
Expand Down
44 changes: 19 additions & 25 deletions src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl Rectangle {
///
/// [differential flame graph]: http://www.brendangregg.com/blog/2014-11-09/differential-flame-graphs.html
#[allow(clippy::cognitive_complexity)]
pub fn from_lines<'a, I, W>(opt: &mut Options<'_>, lines: I, writer: W) -> quick_xml::Result<()>
pub fn from_lines<'a, I, W>(opt: &mut Options<'_>, lines: I, writer: W) -> io::Result<()>
where
I: IntoIterator<Item = &'a str>,
W: Write,
Expand Down Expand Up @@ -500,10 +500,10 @@ where
)?;
svg.write_event(Event::End(BytesEnd::new("svg")))?;
svg.write_event(Event::Eof)?;
return Err(quick_xml::Error::Io(io::Error::new(
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"No stack counts found",
)));
));
}

let image_width = opt.image_width.unwrap_or(DEFAULT_IMAGE_WIDTH) as f64;
Expand Down Expand Up @@ -724,9 +724,9 @@ where

buffer.clear();
if has_href {
svg.write_event(&cache_a_end)?;
svg.write_event(cache_a_end.borrow())?;
} else {
svg.write_event(&cache_g_end)?;
svg.write_event(cache_g_end.borrow())?;
}
}

Expand All @@ -746,7 +746,7 @@ fn write_container_start<'a, W: Write>(
cache_g: &mut Event<'_>,
frame: &merge::TimedFrame<'_>,
mut title: &'a str,
) -> quick_xml::Result<(bool, &'a str)> {
) -> io::Result<(bool, &'a str)> {
let frame_attributes = opt
.func_frameattrs
.frameattrs_for_func(frame.location.function);
Expand All @@ -755,18 +755,18 @@ fn write_container_start<'a, W: Write>(
if let Some(frame_attributes) = frame_attributes {
if frame_attributes.attrs.contains_key("xlink:href") {
write_container_attributes(cache_a, frame_attributes);
svg.write_event(cache_a)?;
svg.write_event(cache_a.borrow())?;
has_href = true;
} else {
write_container_attributes(cache_g, frame_attributes);
svg.write_event(cache_g)?;
svg.write_event(cache_g.borrow())?;
}
if let Some(ref t) = frame_attributes.title {
title = t.as_str();
}
} else if let Event::Start(ref mut c) = cache_g {
c.clear_attributes();
svg.write_event(cache_g)?;
svg.write_event(cache_g.borrow())?;
}

Ok((has_href, title))
Expand All @@ -780,10 +780,10 @@ fn write_container_start<'a, W: Write>(
cache_g: &mut Event<'_>,
_frame: &merge::TimedFrame<'_>,
title: &'a str,
) -> quick_xml::Result<(bool, &'a str)> {
) -> io::Result<(bool, &'a str)> {
if let Event::Start(ref mut c) = cache_g {
c.clear_attributes();
svg.write_event(&cache_g)?;
svg.write_event(cache_g.borrow())?;
}

Ok((false, title))
Expand All @@ -810,7 +810,7 @@ fn write_container_attributes(event: &mut Event<'_>, frame_attributes: &FrameAtt
/// See [`from_lines`] for the expected format of each line.
///
/// The resulting flame graph will be written out to `writer` in SVG format.
pub fn from_reader<R, W>(opt: &mut Options<'_>, reader: R, writer: W) -> quick_xml::Result<()>
pub fn from_reader<R, W>(opt: &mut Options<'_>, reader: R, writer: W) -> io::Result<()>
where
R: Read,
W: Write,
Expand All @@ -823,17 +823,15 @@ where
/// See [`from_lines`] for the expected format of each line.
///
/// The resulting flame graph will be written out to `writer` in SVG format.
pub fn from_readers<R, W>(opt: &mut Options<'_>, readers: R, writer: W) -> quick_xml::Result<()>
pub fn from_readers<R, W>(opt: &mut Options<'_>, readers: R, writer: W) -> io::Result<()>
where
R: IntoIterator,
R::Item: Read,
W: Write,
{
let mut input = String::new();
for mut reader in readers {
reader
.read_to_string(&mut input)
.map_err(quick_xml::Error::Io)?;
reader.read_to_string(&mut input)?;
}
from_lines(opt, input.lines(), writer)
}
Expand All @@ -842,17 +840,13 @@ where
/// and write the result to provided `writer`.
///
/// If files is empty, STDIN will be used as input.
pub fn from_files<W: Write>(
opt: &mut Options<'_>,
files: &[PathBuf],
writer: W,
) -> quick_xml::Result<()> {
pub fn from_files<W: Write>(opt: &mut Options<'_>, files: &[PathBuf], writer: W) -> io::Result<()> {
if files.is_empty() || files.len() == 1 && files[0].to_str() == Some("-") {
let stdin = io::stdin();
let r = BufReader::with_capacity(128 * 1024, stdin.lock());
from_reader(opt, r, writer)
} else if files.len() == 1 {
let r = File::open(&files[0]).map_err(quick_xml::Error::Io)?;
let r = File::open(&files[0])?;
from_reader(opt, r, writer)
} else {
let stdin = io::stdin();
Expand All @@ -866,7 +860,7 @@ pub fn from_files<W: Write>(
stdin_added = true;
}
} else {
let r = File::open(infile).map_err(quick_xml::Error::Io)?;
let r = File::open(infile)?;
readers.push(Box::new(r));
}
}
Expand All @@ -892,7 +886,7 @@ fn filled_rectangle<W: Write>(
rect: &Rectangle,
color: Color,
cache_rect: &mut Event<'_>,
) -> quick_xml::Result<()> {
) -> io::Result<()> {
let x = write!(buffer, "{:.4}%", rect.x1_pct);
let y = write_usize(buffer, rect.y1);
let width = write!(buffer, "{:.4}%", rect.width_pct());
Expand All @@ -916,7 +910,7 @@ fn filled_rectangle<W: Write>(
} else {
unreachable!("cache wrapper was of wrong type: {:?}", cache_rect);
}
svg.write_event(cache_rect)
svg.write_event(cache_rect.borrow())
}

fn write_usize(buffer: &mut StrStack, value: usize) -> usize {
Expand Down
10 changes: 5 additions & 5 deletions src/flamegraph/svg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::cell::RefCell;
use std::io::prelude::*;
use std::io::{self, prelude::*};
use std::iter;

use quick_xml::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Event};
Expand Down Expand Up @@ -59,7 +59,7 @@ pub(super) fn write_header<W>(
svg: &mut Writer<W>,
imageheight: usize,
opt: &Options<'_>,
) -> quick_xml::Result<()>
) -> io::Result<()>
where
W: Write,
{
Expand Down Expand Up @@ -91,7 +91,7 @@ pub(super) fn write_prelude<W>(
svg: &mut Writer<W>,
style_options: &StyleOptions,
opt: &Options<'_>,
) -> quick_xml::Result<()>
) -> io::Result<()>
where
W: Write,
{
Expand Down Expand Up @@ -261,7 +261,7 @@ pub(super) fn write_str<'a, W, I>(
svg: &mut Writer<W>,
buf: &mut StrStack,
item: TextItem<'a, I>,
) -> quick_xml::Result<()>
) -> std::io::Result<()>
where
W: Write,
I: IntoIterator<Item = (&'a str, &'a str)>,
Expand Down Expand Up @@ -290,7 +290,7 @@ where
unreachable!("cache wrapper was of wrong type: {:?}", start_event);
}

svg.write_event(&*start_event.borrow())
svg.write_event(start_event.borrow().borrow())
})?;
let s = match text {
TextArgument::String(ref s) => s,
Expand Down
6 changes: 3 additions & 3 deletions tests/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn test_flamegraph(
input_file: &str,
expected_result_file: &str,
options: Options<'_>,
) -> quick_xml::Result<()> {
) -> io::Result<()> {
test_flamegraph_multiple_files(
vec![PathBuf::from_str(input_file).unwrap()],
expected_result_file,
Expand All @@ -29,7 +29,7 @@ fn test_flamegraph_multiple_files(
input_files: Vec<PathBuf>,
expected_result_file: &str,
mut options: Options<'_>,
) -> quick_xml::Result<()> {
) -> io::Result<()> {
// Always pretty print XML to make it easier to find differences when tests fail.
options.pretty_xml = true;
// Never include static JavaScript in tests so we don't have to have it duplicated
Expand All @@ -45,7 +45,7 @@ fn test_flamegraph_multiple_files(
flamegraph::from_files(&mut options, &input_files, &mut f)?;
fs::metadata(expected_result_file).unwrap()
} else {
return Err(e.into());
return Err(e);
}
}
};
Expand Down

0 comments on commit cf4f325

Please sign in to comment.