Skip to content

Commit

Permalink
Address out of memory issue (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrydallacroce authored Mar 24, 2020
1 parent 7bedbf4 commit 9714e70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Parser/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct($delimiter, $quote, $escape, array $record_end)
$this->escape = $escape;
$this->reset();
$this->machine = new StateMachine();
$this->machine->stopRecording();
}

public function feed(string $chunk)
Expand Down Expand Up @@ -213,6 +214,7 @@ public static function hydrate($json)
$p = $reflector->getProperty('machine');
$p->setAccessible(true);
$machine = new StateMachine();
$machine->stopRecording();
$machine = MachineOfMachines::hydrate(json_encode($data->machine), $machine);

$p->setValue($object, $machine);
Expand Down
10 changes: 5 additions & 5 deletions src/Parser/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct()

$this->addEndState(self::STATE_NEW_FIELD);
$this->addEndState(self::STATE_RECORD_END);

$this->addNewFieldTransitions();
$this->addNoCaptureTransitions();
$this->addRecordEndTransitions();
Expand All @@ -44,10 +44,10 @@ public function __construct()
$this->addQuoteEscapeTransitions();
$this->addQuoteFinalTransitions();
}

private function addNewFieldTransitions()
{
$this->recordEndAndNewFielCommons(self::STATE_NEW_FIELD);
$this->recordEndAndNewFieldCommons(self::STATE_NEW_FIELD);

$this->addTransition(
self::STATE_NEW_FIELD,
Expand Down Expand Up @@ -100,7 +100,7 @@ private function addNoCaptureTransitions()
);
}

private function recordEndAndNewFielCommons($state)
private function recordEndAndNewFieldCommons($state)
{
$this->addTransition(
$state,
Expand Down Expand Up @@ -129,7 +129,7 @@ private function recordEndAndNewFielCommons($state)

private function addRecordEndTransitions()
{
$this->recordEndAndNewFielCommons(self::STATE_RECORD_END);
$this->recordEndAndNewFieldCommons(self::STATE_RECORD_END);

$this->addTransition(
self::STATE_RECORD_END,
Expand Down

0 comments on commit 9714e70

Please sign in to comment.