[cfe-commits] r49774 - in /cfe/trunk: include/clang/Rewrite/Rewriter.h lib/Rewrite/HTMLRewrite.cpp

Chris Lattner sabre at nondot.org
Tue Apr 15 21:33:24 PDT 2008


Author: lattner
Date: Tue Apr 15 23:33:23 2008
New Revision: 49774

URL: http://llvm.org/viewvc/llvm-project?rev=49774&view=rev
Log:
In html::EscapeText, instead of going through the rewriter with
a SourceLocation to get a RewriteBuffer, poke the RewriteBuffer
with an offset directly.  THis is no faster, but results in 
cleaner code.

Modified:
    cfe/trunk/include/clang/Rewrite/Rewriter.h
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=49774&r1=49773&r2=49774&view=diff

==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Tue Apr 15 23:33:23 2008
@@ -51,30 +51,6 @@
   iterator end() const { return Buffer.end(); }
   unsigned size() const { return Buffer.size(); }
   
-private:  // Methods only usable by Rewriter.
-  
-  /// Initialize - Start this rewrite buffer out with a copy of the unmodified
-  /// input buffer.
-  void Initialize(const char *BufStart, const char *BufEnd) {
-    Buffer.assign(BufStart, BufEnd);
-  }
-  
-  /// getMappedOffset - Given an offset into the original SourceBuffer that this
-  /// RewriteBuffer is based on, map it into the offset space of the
-  /// RewriteBuffer.  If AfterInserts is true and if the OrigOffset indicates a
-  /// position where text is inserted, the location returned will be after any
-  /// inserted text at the position.
-  unsigned getMappedOffset(unsigned OrigOffset,
-                           bool AfterInserts = false) const{
-    return Deltas.getDeltaAt(OrigOffset+AfterInserts)+OrigOffset;
-  }
-  
-  /// AddDelta - When a change is made that shifts around the text buffer, this
-  /// method is used to record that info.
-  void AddDelta(unsigned OrigOffset, int Change) {
-    return Deltas.AddDelta(OrigOffset, Change);
-  }
-  
   /// RemoveText - Remove the specified text.
   void RemoveText(unsigned OrigOffset, unsigned Size);
   
@@ -110,6 +86,29 @@
   void ReplaceText(unsigned OrigOffset, unsigned OrigLength,
                    const char *NewStr, unsigned NewLength);
   
+private:  // Methods only usable by Rewriter.
+  
+  /// Initialize - Start this rewrite buffer out with a copy of the unmodified
+  /// input buffer.
+  void Initialize(const char *BufStart, const char *BufEnd) {
+    Buffer.assign(BufStart, BufEnd);
+  }
+  
+  /// getMappedOffset - Given an offset into the original SourceBuffer that this
+  /// RewriteBuffer is based on, map it into the offset space of the
+  /// RewriteBuffer.  If AfterInserts is true and if the OrigOffset indicates a
+  /// position where text is inserted, the location returned will be after any
+  /// inserted text at the position.
+  unsigned getMappedOffset(unsigned OrigOffset,
+                           bool AfterInserts = false) const{
+    return Deltas.getDeltaAt(OrigOffset+AfterInserts)+OrigOffset;
+  }
+  
+  /// AddDelta - When a change is made that shifts around the text buffer, this
+  /// method is used to record that info.
+  void AddDelta(unsigned OrigOffset, int Change) {
+    return Deltas.AddDelta(OrigOffset, Change);
+  }
 };
   
 

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=49774&r1=49773&r2=49774&view=diff

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Apr 15 23:33:23 2008
@@ -30,49 +30,38 @@
   
   assert (C <= FileEnd);
   
+  RewriteBuffer &RB = R.getEditBuffer(FileID);
+  
   for (unsigned FilePos = 0; C != FileEnd ; ++C, ++FilePos) {
       
     switch (*C) {
-      default: break;
-        
-      case ' ':
-        if (EscapeSpaces) {
-          SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-          R.ReplaceText(Loc, 1, " ", 6);
-        }
-        break;
-
-      case '\t': {
-        if (!ReplaceTabs)
-          break;
-        
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        
-        if (EscapeSpaces)
-          R.ReplaceText(Loc, 1, "    ", 6*4);
-        else
-          R.ReplaceText(Loc, 1, "    ", 4);
-        
-        break;
-      }
-        
-      case '<': {
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        R.ReplaceText(Loc, 1, "<", 4);
-        break;
-      }
-        
-      case '>': {
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        R.ReplaceText(Loc, 1, ">", 4);
-        break;
-      }
-        
-      case '&': {
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        R.ReplaceText(Loc, 1, "&", 5);
-        break;
-      }
+    default: break;
+      
+    case ' ':
+      if (EscapeSpaces)
+        RB.ReplaceText(FilePos, 1, " ", 6);
+      break;
+
+    case '\t':
+      if (!ReplaceTabs)
+        break;
+      if (EscapeSpaces)
+        RB.ReplaceText(FilePos, 1, "    ", 6*4);
+      else
+        RB.ReplaceText(FilePos, 1, "    ", 4);
+      break;
+      
+    case '<':
+      RB.ReplaceText(FilePos, 1, "<", 4);
+      break;
+      
+    case '>':
+      RB.ReplaceText(FilePos, 1, ">", 4);
+      break;
+      
+    case '&':
+      RB.ReplaceText(FilePos, 1, "&", 5);
+      break;
     }
   }
 }
@@ -98,7 +87,8 @@
         
         case '\t':
           if (ReplaceTabs)
-            for (unsigned i = 0; i < 4; ++i) os << " ";
+            for (unsigned i = 0; i < 4; ++i)
+              os << " ";
           else os << c;
         
           break;





More information about the cfe-commits mailing list