Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions marked-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ fn main() {
if rustv < msrv {
panic!(
"{} v{} {} is {} > {} (this rustc)",
PACKAGE, VERSION, M_V, join(&msrv), join(&rustv));
PACKAGE,
VERSION,
M_V,
join(&msrv),
join(&rustv)
);
}
}

fn join(ver: &[u16]) -> String {
let mut out = String::new();
for v in ver {
if !out.is_empty() { out.push('.'); }
if !out.is_empty() {
out.push('.');
}
out.push_str(&v.to_string());
}
out
Expand All @@ -39,9 +46,7 @@ fn rustc_version() -> Vec<u16> {
}
let mut vp = v.split("-");
if let Some(v) = vp.next() {
let vs: Vec<u16> = v.split(".")
.filter_map(|vss| vss.parse().ok())
.collect();
let vs: Vec<u16> = v.split(".").filter_map(|vss| vss.parse().ok()).collect();
if !vs.is_empty() {
return vs;
}
Expand Down
38 changes: 16 additions & 22 deletions marked-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

use std::error::Error as StdError;
use std::fmt;
use std::fs::File;
use std::io;
use std::process;
use std::fs::File;

use encoding_rs as enc;

use marked::{
chain_filters,
filter,
html::parse_buffered,
logger::setup_logger,
EncodingHint,
};
use marked::{chain_filters, filter, html::parse_buffered, logger::setup_logger, EncodingHint};

use clap::{
crate_version,
Arg, App, AppSettings, SubCommand,
};
use clap::{crate_version, App, AppSettings, Arg, SubCommand};

use log::{debug, error};

Expand Down Expand Up @@ -55,8 +46,7 @@ fn run() -> Result<(), Flaw> {
let html = SubCommand::with_name("html")
.setting(AppSettings::DeriveDisplayOrder)
.about("HTML processing")
.after_help(
"Parses input, applies filters, and serializes to output.")
.after_help("Parses input, applies filters, and serializes to output.")
.args(&[
Arg::with_name("output")
.short("o")
Expand All @@ -80,7 +70,7 @@ fn run() -> Result<(), Flaw> {
Arg::with_name("file")
.required(false)
.value_name("INPUT-FILE")
.help("File path to read (default: STDIN)")
.help("File path to read (default: STDIN)"),
]);

let app = App::new("marked")
Expand All @@ -89,12 +79,14 @@ fn run() -> Result<(), Flaw> {
.setting(AppSettings::SubcommandRequired)
.setting(AppSettings::DeriveDisplayOrder)
.max_term_width(100)
.arg(Arg::with_name("debug")
.short("d")
.long("debug")
.multiple(true)
.help("Enable more logging, and up to `-dddd`")
.global(true))
.arg(
Arg::with_name("debug")
.short("d")
.long("debug")
.multiple(true)
.help("Enable more logging, and up to `-dddd`")
.global(true),
)
.subcommand(html);

let mtch = app.get_matches();
Expand Down Expand Up @@ -148,7 +140,9 @@ fn run() -> Result<(), Flaw> {
} else {
quit!(
"input {} same as output {} not supported",
fin.unwrap(), fout);
fin.unwrap(),
fout
);
}
} else {
Box::new(io::stdout())
Expand Down
46 changes: 16 additions & 30 deletions marked/benches/round_trip.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
#![warn(rust_2018_idioms)]

#![feature(test)]
extern crate test; // Still required, see rust-lang/rust#55133

use std::default::Default;
use std::io;
use std::fs::File;
use std::io;

use test::Bencher;

use encoding_rs as enc;
use html5ever::driver::ParseOpts;
use html5ever::parse_document;
use markup5ever_rcdom::{SerializableHandle, RcDom};
use html5ever::serialize as rc_serialize;
use markup5ever_rcdom::{RcDom, SerializableHandle};

use marked;
use marked::{Decoder, Document, EncodingHint};
use marked::chain_filters;
use marked::filter;
use marked::html::parse_buffered;
use marked::{Decoder, Document, EncodingHint};

#[bench]
fn b00_round_trip_rcdom(b: &mut Bencher) {
b.iter(|| {
let parser_sink =
parse_document(RcDom::default(), ParseOpts::default());
let parser_sink = parse_document(RcDom::default(), ParseOpts::default());
let decoder = Decoder::new(enc::UTF_8, parser_sink);
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let doc = decoder.read_to_end(&mut fin).expect("parse");
let mut out = Vec::with_capacity(273108);
let ser_handle: SerializableHandle = doc.document.clone().into();
rc_serialize(&mut out, &ser_handle, Default::default())
.expect("serialization");
rc_serialize(&mut out, &ser_handle, Default::default()).expect("serialization");
assert_eq!(out.len(), 272273);
});
}

#[bench]
fn b01_round_trip_marked(b: &mut Bencher) {
b.iter(|| {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let doc = parse_buffered(eh, &mut fin).expect("parse");
let mut out = Vec::with_capacity(273108);
Expand All @@ -54,8 +49,7 @@ fn b01_round_trip_marked(b: &mut Bencher) {
#[bench]
fn b11_decode_eucjp_parse_marked(b: &mut Bencher) {
b.iter(|| {
let mut fin = sample_file("matsunami_eucjp_meta.html")
.expect("sample_file");
let mut fin = sample_file("matsunami_eucjp_meta.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
parse_buffered(eh, &mut fin).expect("parse");
});
Expand All @@ -64,8 +58,7 @@ fn b11_decode_eucjp_parse_marked(b: &mut Bencher) {
#[bench]
fn b12_decode_windows1251_parse_marked(b: &mut Bencher) {
b.iter(|| {
let mut fin = sample_file("russez_windows1251_meta.html")
.expect("sample_file");
let mut fin = sample_file("russez_windows1251_meta.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
parse_buffered(eh, &mut fin).expect("parse");
});
Expand All @@ -74,17 +67,15 @@ fn b12_decode_windows1251_parse_marked(b: &mut Bencher) {
#[bench]
fn b13_utf8_parse_marked(b: &mut Bencher) {
b.iter(|| {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
parse_buffered(eh, &mut fin).expect("parse");
});
}

#[bench]
fn b20_text_content(b: &mut Bencher) {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let doc = parse_buffered(eh, &mut fin).expect("parse");

Expand All @@ -96,8 +87,7 @@ fn b20_text_content(b: &mut Bencher) {

#[bench]
fn b30_text_normalize_content(b: &mut Bencher) {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let doc = parse_buffered(eh, &mut fin).expect("parse");
b.iter(|| {
Expand All @@ -110,8 +100,7 @@ fn b30_text_normalize_content(b: &mut Bencher) {

#[bench]
fn b31_text_normalize_content_identity(b: &mut Bencher) {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
doc.filter(chain_filters!(
Expand Down Expand Up @@ -144,8 +133,7 @@ fn b31_text_normalize_content_identity(b: &mut Bencher) {

#[bench]
fn b50_sparse_bulk_clone(b: &mut Bencher) {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
filter_all(&mut doc);
Expand All @@ -157,8 +145,7 @@ fn b50_sparse_bulk_clone(b: &mut Bencher) {

#[bench]
fn b51_sparse_compact(b: &mut Bencher) {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
filter_all(&mut doc);
Expand All @@ -171,8 +158,7 @@ fn b51_sparse_compact(b: &mut Bencher) {

#[bench]
fn b52_sparse_deep_clone(b: &mut Bencher) {
let mut fin = sample_file("github-dekellum.html")
.expect("sample_file");
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
let eh = EncodingHint::shared_default(enc::UTF_8);
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
filter_all(&mut doc);
Expand Down
15 changes: 10 additions & 5 deletions marked/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ fn main() {
if rustv < msrv {
panic!(
"{} v{} {} is {} > {} (this rustc)",
PACKAGE, VERSION, M_V, join(&msrv), join(&rustv));
PACKAGE,
VERSION,
M_V,
join(&msrv),
join(&rustv)
);
}
}

fn join(ver: &[u16]) -> String {
let mut out = String::new();
for v in ver {
if !out.is_empty() { out.push('.'); }
if !out.is_empty() {
out.push('.');
}
out.push_str(&v.to_string());
}
out
Expand All @@ -39,9 +46,7 @@ fn rustc_version() -> Vec<u16> {
}
let mut vp = v.split("-");
if let Some(v) = vp.next() {
let vs: Vec<u16> = v.split(".")
.filter_map(|vss| vss.parse().ok())
.collect();
let vs: Vec<u16> = v.split(".").filter_map(|vss| vss.parse().ok()).collect();
if !vs.is_empty() {
return vs;
}
Expand Down
Loading