Skip to content

Instantly share code, notes, and snippets.

@koivunej
Last active February 16, 2017 09:52
Show Gist options
  • Save koivunej/2f6dd73508cd9bca29403175ebc71817 to your computer and use it in GitHub Desktop.
Save koivunej/2f6dd73508cd9bca29403175ebc71817 to your computer and use it in GitHub Desktop.
Applies on top of 4f939ddf0c9344da646367d46810eb1ac92c5780

Not sending this as a PR as I assume it's too dirty hack. data_types.rs used can be found at: https://github.com/tafia/quick-protobuf/blob/master/examples/codegen/data_types.rs

time rustfmt --write-mode=display data_types.rs >/dev/null timings:

rustfmt: installed with rustup run nightly cargo install rustfmt

real    1m14.506s
real    1m15.186s
real    1m14.968s
real    1m15.400s
real    1m15.301s

rustfmt@4f939ddf0c9344da646367d46810eb1ac92c5780: opt-level=3 without regex-skip.patch

real    1m15.438s
real    1m15.894s
real    1m16.135s
real    1m17.462s
real    1m16.344s

rustfmt: opt-level=3 with regex-skip.patch

real    0m49.870s
real    0m49.298s
real    0m50.049s
real    0m49.146s
real    0m50.813s
diff --git a/Cargo.toml b/Cargo.toml
index 75f2f69..e769365 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,6 +30,7 @@ env_logger = "0.3"
getopts = "0.2"
itertools = "0.5.8"
multimap = "0.3"
+lazy_static = "0.2"
[build-dependencies]
walkdir = "1.0.3"
diff --git a/src/comment.rs b/src/comment.rs
index b7549f1..decdcad 100644
--- a/src/comment.rs
+++ b/src/comment.rs
@@ -574,8 +574,15 @@ pub fn recover_comment_removed(new: String,
context: &RewriteContext,
shape: Shape)
-> Option<String> {
+
+ use regex::Regex;
+ lazy_static! {
+ static ref RE: Regex = Regex::new("/[*/]").unwrap();
+ }
+
let snippet = context.snippet(span);
- if changed_comment_content(&snippet, &new) {
+
+ if RE.is_match(&snippet) && changed_comment_content(&snippet, &new) {
// We missed some comments
// Keep previous formatting if it satisfies the constrains
wrap_str(snippet, context.config.max_width, shape)
diff --git a/src/lib.rs b/src/lib.rs
index abe9a6e..7ca540e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,6 +28,9 @@ extern crate term;
extern crate itertools;
extern crate multimap;
+#[macro_use]
+extern crate lazy_static;
+
use errors::{Handler, DiagnosticBuilder};
use errors::emitter::{ColorConfig, EmitterWriter};
use syntax::ast;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment