[Mlir-commits] [mlir] 731206f - [mlir] Move move capture in SparseElementsAttr::getValues

River Riddle llvmlistbot at llvm.org
Tue May 11 12:18:34 PDT 2021


Author: River Riddle
Date: 2021-05-11T12:09:42-07:00
New Revision: 731206f3684af5979e3a794970db83f9a34b4541

URL: https://github.com/llvm/llvm-project/commit/731206f3684af5979e3a794970db83f9a34b4541
DIFF: https://github.com/llvm/llvm-project/commit/731206f3684af5979e3a794970db83f9a34b4541.diff

LOG: [mlir] Move move capture in SparseElementsAttr::getValues

This was a TODO for the move to C++14. Now that the move has been completed, we can resolve it.

Added: 
    

Modified: 
    mlir/include/mlir/IR/BuiltinAttributes.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/BuiltinAttributes.h b/mlir/include/mlir/IR/BuiltinAttributes.h
index 2e6677c12c79..af75c2e9401a 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.h
+++ b/mlir/include/mlir/IR/BuiltinAttributes.h
@@ -780,15 +780,17 @@ auto SparseElementsAttr::getValues() const
   auto zeroValue = getZeroValue<T>();
   auto valueIt = getValues().getValues<T>().begin();
   const std::vector<ptr
diff _t> flatSparseIndices(getFlattenedSparseIndices());
-  // TODO: Move-capture flatSparseIndices when c++14 is available.
-  std::function<T(ptr
diff _t)> mapFn = [=](ptr
diff _t index) {
-    // Try to map the current index to one of the sparse indices.
-    for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i)
-      if (flatSparseIndices[i] == index)
-        return *std::next(valueIt, i);
-    // Otherwise, return the zero value.
-    return zeroValue;
-  };
+  std::function<T(ptr
diff _t)> mapFn =
+      [flatSparseIndices{std::move(flatSparseIndices)},
+       valueIt{std::move(valueIt)},
+       zeroValue{std::move(zeroValue)}](ptr
diff _t index) {
+        // Try to map the current index to one of the sparse indices.
+        for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i)
+          if (flatSparseIndices[i] == index)
+            return *std::next(valueIt, i);
+        // Otherwise, return the zero value.
+        return zeroValue;
+      };
   return llvm::map_range(llvm::seq<ptr
diff _t>(0, getNumElements()), mapFn);
 }
 


        


More information about the Mlir-commits mailing list