-void formatted_raw_ostream::ComputeColumn() {
- // The buffer may have been allocated underneath us.
- if (Scanned == 0) Scanned = begin();
- // Scan all characters added since our last scan to determine the new column.
- ColumnScanned = CountColumns(ColumnScanned, Scanned, end() - Scanned);
- // We're now current with everything in the buffer.
- Scanned = end();
+void formatted_raw_ostream::ComputeColumn(const char *Ptr, size_t Size) {
+ // If our previous scan pointer is inside the buffer, assume we already
+ // scanned those bytes. This depends on raw_ostream to not change our buffer
+ // in unexpected ways.
+ if (Ptr <= Scanned && Scanned <= Ptr + Size) {
+ // Scan all characters added since our last scan to determine the new
+ // column.
+ ColumnScanned = CountColumns(ColumnScanned, Scanned,
+ Size - (Scanned - Ptr));
+ } else
+ ColumnScanned = CountColumns(ColumnScanned, Ptr, Size);
+
+ // Update the scanning pointer.
+ Scanned = Ptr + Size;