Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(783)

Unified Diff: tracing/tracing/importer/simple_line_reader.html

Issue 2755943002: tracing: Stream processing for some importers (Closed)
Patch Set: review / sync Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tracing/tracing/importer/simple_line_reader.html
diff --git a/tracing/tracing/importer/simple_line_reader.html b/tracing/tracing/importer/simple_line_reader.html
index 636c9e88585a58534928378811ad399703399432..2fea194a68c4001f93096f42539123fd194d1798 100644
--- a/tracing/tracing/importer/simple_line_reader.html
+++ b/tracing/tracing/importer/simple_line_reader.html
@@ -9,42 +9,75 @@ found in the LICENSE file.
'use strict';
tr.exportTo('tr.importer', function() {
- /**
- * @constructor
- */
- function SimpleLineReader(text) {
- this.lines_ = text.split('\n');
- this.curLine_ = 0;
-
- this.savedLines_ = undefined;
- }
+ class SimpleLineReader {
+ constructor(text) {
+ this.data_ = text instanceof tr.b.TraceStream ? text : text.split('\n');
+ this.curLine_ = 0;
+ this.readLastLine_ = false;
+ this.savedLines_ = undefined;
+ }
- SimpleLineReader.prototype = {
- advanceToLineMatching: function(regex) {
- for (; this.curLine_ < this.lines_.length; this.curLine_++) {
- var line = this.lines_[this.curLine_];
- if (this.savedLines_ !== undefined) {
- this.savedLines_.push(line);
+ * [Symbol.iterator]() {
+ let lastLine = undefined;
+ while (this.hasData_) {
+ if (this.readLastLine_) {
+ this.curLine_++;
+ this.readLastLine_ = false;
+ } else if (this.data_ instanceof tr.b.TraceStream) {
+ this.curLine_++;
+ let line = this.data_.readUntilDelimiter('\n');
+ lastLine = line.endsWith('\n') ? line.slice(0, -1) : line;
+ } else {
+ this.curLine_++;
+ lastLine = this.data_[this.curLine_ - 1];
}
- if (regex.test(line)) return true;
+ yield lastLine;
}
- return false;
- },
+ }
get curLineNumber() {
return this.curLine_;
- },
+ }
+
+ get hasData_() {
+ if (this.data_ instanceof tr.b.TraceStream) return this.data_.hasData;
+ return this.curLine_ < this.data_.length;
+ }
+
+ advanceToLineMatching(regex) {
+ for (const line of this) {
+ if (this.savedLines_ !== undefined) this.savedLines_.push(line);
+ if (regex.test(line)) {
+ this.goBack_();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ goBack_() {
+ if (this.readLastLine_) {
+ throw new Error('There should be at least one nextLine call between ' +
+ 'any two goBack calls.');
+ }
+ if (this.curLine_ === 0) {
+ throw new Error('There should be at least one nextLine call before ' +
+ 'the first goBack call.');
+ }
+ this.readLastLine_ = true;
+ this.curLine_--;
+ }
- beginSavingLines: function() {
+ beginSavingLines() {
this.savedLines_ = [];
- },
+ }
- endSavingLinesAndGetResult: function() {
+ endSavingLinesAndGetResult() {
var tmp = this.savedLines_;
this.savedLines_ = undefined;
return tmp;
}
- };
+ }
return {
SimpleLineReader,
« no previous file with comments | « tracing/tracing/extras/importer/trace_event_importer_test.html ('k') | tracing/tracing/mre/file_handle.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698