]> granicus.if.org Git - clang/commitdiff
[AST] Use std::copy and std::fill to simplify some memcpy and memset calls. Also...
authorCraig Topper <craig.topper@gmail.com>
Sat, 5 Dec 2015 07:41:44 +0000 (07:41 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sat, 5 Dec 2015 07:41:44 +0000 (07:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254846 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h

index 16dde19fda94c8186e902d4fbb297309859a070b..1d1a99ed69079b48b2c70b11bf8fbbb6714da4b0 100644 (file)
@@ -825,18 +825,20 @@ class AttributedStmt : public Stmt {
   AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
     : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
       NumAttrs(Attrs.size()) {
-    memcpy(getAttrArrayPtr(), Attrs.data(), Attrs.size() * sizeof(Attr *));
+    std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
   }
 
   explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
     : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
-    memset(getAttrArrayPtr(), 0, NumAttrs * sizeof(Attr *));
+    std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
   }
 
-  Attr *const *getAttrArrayPtr() const {
-    return reinterpret_cast<Attr *const *>(this + 1);
+  const Attr *const *getAttrArrayPtr() const {
+    return reinterpret_cast<const Attr *const *>(this + 1);
+  }
+  const Attr **getAttrArrayPtr() {
+    return reinterpret_cast<const Attr **>(this + 1);
   }
-  Attr **getAttrArrayPtr() { return reinterpret_cast<Attr **>(this + 1); }
 
 public:
   static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,