]> granicus.if.org Git - clang/commitdiff
don't new[] an empty array when an AttributeList has
authorChris Lattner <sabre@nondot.org>
Thu, 19 Feb 2009 06:25:12 +0000 (06:25 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Feb 2009 06:25:12 +0000 (06:25 +0000)
zero expression arguments.  This eliminates 2579 1-byte
mallocs when parsing Cocoa.h.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65022 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/AttributeList.cpp

index 3d9d2b45f782342547749d7d955bb8a44a2551a2..6b58a001bca95fa684f3911efa671060b0de3ac3 100644 (file)
@@ -16,13 +16,17 @@ using namespace clang;
 
 AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
                              IdentifierInfo *pName, SourceLocation pLoc,
-                             Action::ExprTy **elist, unsigned numargs,
+                             Action::ExprTy **ExprList, unsigned numArgs,
                              AttributeList *n)
   : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
-    NumArgs(numargs), Next(n) {
-  Args = new Action::ExprTy*[numargs];
-  for (unsigned i = 0; i != numargs; ++i)
-    Args[i] = elist[i];
+    NumArgs(numArgs), Next(n) {
+  
+  if (numArgs == 0)
+    Args = 0;
+  else {
+    Args = new Action::ExprTy*[numArgs];
+    memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
+  }
 }
 
 AttributeList::~AttributeList() {