about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authorSeiichi Uchida <topecongiro@localhost.localdomain>2017-05-27 18:48:42 +0900
committerSeiichi Uchida <topecongiro@localhost.localdomain>2017-05-27 21:56:23 +0900
commita22228aceea355098745a314b4177a800a623e97 (patch)
tree329b17795dd527583b8a3619fb969496600aa5b5 /src/expr.rs
parent8ac3fc36cc98f66381759ae4b8ef08021ec102a2 (diff)
Avoid unnecessary binary search in rewrite_call
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 21a872489d8..4c9a55f28c0 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -74,7 +74,7 @@ fn format_expr(expr: &ast::Expr,
         }
         ast::ExprKind::Call(ref callee, ref args) => {
             let inner_span = mk_sp(callee.span.hi, expr.span.hi);
-            rewrite_call(context, &**callee, args, inner_span, shape)
+            rewrite_call_with_binary_search(context, &**callee, args, inner_span, shape)
         }
         ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape),
         ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => {
@@ -1603,41 +1603,47 @@ fn string_requires_rewrite(context: &RewriteContext,
     false
 }
 
-pub fn rewrite_call<R>(context: &RewriteContext,
-                       callee: &R,
-                       args: &[ptr::P<ast::Expr>],
-                       span: Span,
-                       shape: Shape)
-                       -> Option<String>
+pub fn rewrite_call_with_binary_search<R>(context: &RewriteContext,
+                                          callee: &R,
+                                          args: &[ptr::P<ast::Expr>],
+                                          span: Span,
+                                          shape: Shape)
+                                          -> Option<String>
     where R: Rewrite
 {
     let closure = |callee_max_width| {
-        rewrite_call_inner(context, callee, callee_max_width, args, span, shape, false)
+        // FIXME using byte lens instead of char lens (and probably all over the
+        // place too)
+        let callee_shape = Shape {
+            width: callee_max_width,
+            ..shape
+        };
+        let callee_str = callee
+            .rewrite(context, callee_shape)
+            .ok_or(Ordering::Greater)?;
+
+        rewrite_call_inner(context, &callee_str, args, span, shape, false)
     };
 
     binary_search(1, shape.width, closure)
 }
 
-fn rewrite_call_inner<R>(context: &RewriteContext,
-                         callee: &R,
-                         max_callee_width: usize,
-                         args: &[ptr::P<ast::Expr>],
-                         span: Span,
-                         shape: Shape,
-                         force_trailing_comma: bool)
-                         -> Result<String, Ordering>
-    where R: Rewrite
-{
-    // FIXME using byte lens instead of char lens (and probably all over the
-    // place too)
-    let callee_shape = Shape {
-        width: max_callee_width,
-        ..shape
-    };
-    let callee_str = callee
-        .rewrite(context, callee_shape)
-        .ok_or(Ordering::Greater)?;
+pub fn rewrite_call(context: &RewriteContext,
+                    callee: &str,
+                    args: &[ptr::P<ast::Expr>],
+                    span: Span,
+                    shape: Shape)
+                    -> Option<String> {
+    rewrite_call_inner(context, &callee, args, span, shape, false).ok()
+}
 
+fn rewrite_call_inner(context: &RewriteContext,
+                      callee_str: &str,
+                      args: &[ptr::P<ast::Expr>],
+                      span: Span,
+                      shape: Shape,
+                      force_trailing_comma: bool)
+                      -> Result<String, Ordering> {
     // 2 = `( `, 1 = `(`
     let paren_overhead = if context.config.spaces_within_parens() {
         2
@@ -2108,7 +2114,6 @@ pub fn rewrite_tuple(context: &RewriteContext,
     // 1 = ","
     rewrite_call_inner(context,
                        &String::new(),
-                       shape.width.checked_sub(1).unwrap_or(0),
                        items,
                        span,
                        shape,