(Wangle) Don't add an extra value() call for makeFuture(Try)
authorHannes Roth <hannesr@fb.com>
Mon, 26 Jan 2015 17:08:49 +0000 (09:08 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:12:39 +0000 (13:12 -0800)
Summary: Not sure why we'd need that? This avoids a move, I think.

Test Plan:
Run all the tests. Also unbreaks this code, which used to work at some
point.
https://phabricator.fb.com/diffusion/FBCODE/browse/master/taoThriftService/TaoServiceHandler.cpp;a27bc2ef36cd671d65ae0fd2cc1fb1f823e68ae4$246

Reviewed By: hans@fb.com

Subscribers: trunkagent, folly-diffs@, jsedgwick

FB internal diff: D1800619

Signature: t1:1800619:1422053903:f9e65a0be3d820a9a9989b3cf5dfaf2a61e2e900

folly/futures/Future-inl.h

index 4b12706f0661703d55704128f46d14affbcaa269..e14754b792a999ebf604ef06cba88ee4fbb1c496 100644 (file)
@@ -497,11 +497,9 @@ makeFuture(E const& e) {
 
 template <class T>
 Future<T> makeFuture(Try<T>&& t) {
-  if (t.hasException()) {
-    return makeFuture<T>(std::move(t.exception()));
-  } else {
-    return makeFuture<T>(std::move(t.value()));
-  }
+  Promise<typename std::decay<T>::type> p;
+  p.fulfilTry(std::move(t));
+  return p.getFuture();
 }
 
 template <>