]> granicus.if.org Git - clang/commitdiff
In html::EscapeText, instead of going through the rewriter with
authorChris Lattner <sabre@nondot.org>
Wed, 16 Apr 2008 04:33:23 +0000 (04:33 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 16 Apr 2008 04:33:23 +0000 (04:33 +0000)
a SourceLocation to get a RewriteBuffer, poke the RewriteBuffer
with an offset directly.  THis is no faster, but results in
cleaner code.

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

include/clang/Rewrite/Rewriter.h
lib/Rewrite/HTMLRewrite.cpp

index b3b53882c5a73cf0c9f65d0f3ca51463a9880901..6176cfb2dd5c3df15277f5598523edfb704e03d3 100644 (file)
@@ -51,30 +51,6 @@ public:
   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 @@ private:  // Methods only usable by Rewriter.
   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);
+  }
 };
   
 
index fc1627af02940a9b675a54e2633fdef4472f9d0c..b4dbb444313cceb6df0de6883ee2ece25353eeb0 100644 (file)
@@ -30,49 +30,38 @@ void html::EscapeText(Rewriter& R, unsigned FileID,
   
   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, "&nbsp;", 6);
-        }
-        break;
+    default: break;
+      
+    case ' ':
+      if (EscapeSpaces)
+        RB.ReplaceText(FilePos, 1, "&nbsp;", 6);
+      break;
 
-      case '\t': {
-        if (!ReplaceTabs)
-          break;
-        
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        
-        if (EscapeSpaces)
-          R.ReplaceText(Loc, 1, "&nbsp;&nbsp;&nbsp;&nbsp;", 6*4);
-        else
-          R.ReplaceText(Loc, 1, "    ", 4);
-        
-        break;
-      }
-        
-      case '<': {
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        R.ReplaceText(Loc, 1, "&lt;", 4);
-        break;
-      }
-        
-      case '>': {
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        R.ReplaceText(Loc, 1, "&gt;", 4);
+    case '\t':
+      if (!ReplaceTabs)
         break;
-      }
-        
-      case '&': {
-        SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
-        R.ReplaceText(Loc, 1, "&amp;", 5);
-        break;
-      }
+      if (EscapeSpaces)
+        RB.ReplaceText(FilePos, 1, "&nbsp;&nbsp;&nbsp;&nbsp;", 6*4);
+      else
+        RB.ReplaceText(FilePos, 1, "    ", 4);
+      break;
+      
+    case '<':
+      RB.ReplaceText(FilePos, 1, "&lt;", 4);
+      break;
+      
+    case '>':
+      RB.ReplaceText(FilePos, 1, "&gt;", 4);
+      break;
+      
+    case '&':
+      RB.ReplaceText(FilePos, 1, "&amp;", 5);
+      break;
     }
   }
 }
@@ -98,7 +87,8 @@ std::string html::EscapeText(const std::string& s, bool EscapeSpaces,
         
         case '\t':
           if (ReplaceTabs)
-            for (unsigned i = 0; i < 4; ++i) os << "&nbsp;";
+            for (unsigned i = 0; i < 4; ++i)
+              os << "&nbsp;";
           else os << c;
         
           break;