[llvm-commits] [llvm] r104020 - /llvm/trunk/lib/MC/MCContext.cpp

Benjamin Kramer benny.kra at googlemail.com
Tue May 18 05:15:34 PDT 2010


Author: d0k
Date: Tue May 18 07:15:34 2010
New Revision: 104020

URL: http://llvm.org/viewvc/llvm-project?rev=104020&view=rev
Log:
Simplify MCContext::(Next|Get)Instance

- Allocate MCLabels in the context so they don't leak.
- Avoid duplicated densemap lookup.

Modified:
    llvm/trunk/lib/MC/MCContext.cpp

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=104020&r1=104019&r2=104020&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue May 18 07:15:34 2010
@@ -73,33 +73,17 @@
 }
 
 unsigned MCContext::NextInstance(int64_t LocalLabelVal) {
-  unsigned Instance;
-  MCLabel *Label;
-  Label = Instances[LocalLabelVal];
-  if (Label) {
-    Instance = Label->incInstance();
-  }
-  else {
-    Instance = 1;
-    Label = new MCLabel(Instance);
-    Instances[LocalLabelVal] = Label;
-  }
-  return Instance;
+  MCLabel *&Label = Instances[LocalLabelVal];
+  if (!Label)
+    Label = new (*this) MCLabel(0);
+  return Label->incInstance();
 }
 
 unsigned MCContext::GetInstance(int64_t LocalLabelVal) {
-  int Instance;
-  MCLabel *Label;
-  Label = Instances[LocalLabelVal];
-  if (Label) {
-    Instance = Label->getInstance();
-  }
-  else {
-    Instance = 0;
-    Label = new MCLabel(Instance);
-    Instances[LocalLabelVal] = Label;
-  }
-  return Instance;
+  MCLabel *&Label = Instances[LocalLabelVal];
+  if (!Label)
+    Label = new (*this) MCLabel(0);
+  return Label->getInstance();
 }
 
 MCSymbol *MCContext::CreateDirectionalLocalSymbol(int64_t LocalLabelVal) {





More information about the llvm-commits mailing list