22
33const {
44 ArrayPrototypeJoin,
5- ArrayPrototypePush,
65 Boolean,
76 FunctionPrototype,
8- StringPrototypeSplit ,
7+ RegExpPrototypeSymbolSplit ,
98 StringPrototypeTrim,
109} = primordials ;
1110
@@ -18,7 +17,6 @@ let debug = require('internal/util/debuglog').debuglog('repl', (fn) => {
1817} ) ;
1918const permission = require ( 'internal/process/permission' ) ;
2019const { clearTimeout, setTimeout } = require ( 'timers' ) ;
21- const { parseHistoryFromFile } = require ( 'internal/repl/history-utils' ) ;
2220
2321const noop = FunctionPrototype ;
2422
@@ -99,7 +97,7 @@ function setupHistory(repl, historyPath, ready) {
9997 }
10098
10199 if ( data ) {
102- repl . history = parseHistoryFromFile ( data , repl . historySize ) ;
100+ repl . history = RegExpPrototypeSymbolSplit ( / [ \n ] + / , data , repl . historySize ) ;
103101 } else {
104102 repl . history = [ ] ;
105103 }
@@ -136,30 +134,14 @@ function setupHistory(repl, historyPath, ready) {
136134 timer = setTimeout ( flushHistory , kDebounceHistoryMS ) ;
137135 }
138136
139- function parseHistoryData ( ) {
140- const eol = os . EOL ;
141- const result = [ ] ;
142- const historyLength = repl . history . length ;
143-
144- for ( let i = 0 ; i < historyLength ; i ++ ) {
145- const entry = repl . history [ i ] ;
146- const lines = StringPrototypeSplit ( entry , eol ) ;
147- for ( let j = lines . length - 1 ; j >= 0 ; j -- ) {
148- ArrayPrototypePush ( result , lines [ j ] ) ;
149- }
150- }
151-
152- return ArrayPrototypeJoin ( result , eol ) + eol ;
153- }
154-
155137 function flushHistory ( ) {
156138 timer = null ;
157139 if ( writing ) {
158140 pending = true ;
159141 return ;
160142 }
161143 writing = true ;
162- const historyData = parseHistoryData ( ) ;
144+ const historyData = ArrayPrototypeJoin ( repl . history , os . EOL ) ;
163145 fs . write ( repl . _historyHandle , historyData , 0 , 'utf8' , onwritten ) ;
164146 }
165147
0 commit comments