Skip to content

Commit

Permalink
Merge pull request #164 from mhujer/mh-uuid-decoding-speedup
Browse files Browse the repository at this point in the history
Optimize UUID string decoding
  • Loading branch information
ramsey committed Mar 26, 2017
2 parents ff6ad53 + 4eefce3 commit 6a575eb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Codec/StringCodec.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ protected function extractComponents($encodedUuid)
protected function getFields(array $components)
{
return array(
'time_low' => sprintf('%08s', $components[0]),
'time_mid' => sprintf('%04s', $components[1]),
'time_hi_and_version' => sprintf('%04s', $components[2]),
'clock_seq_hi_and_reserved' => sprintf('%02s', substr($components[3], 0, 2)),
'clock_seq_low' => sprintf('%02s', substr($components[3], 2)),
'node' => sprintf('%012s', $components[4])
'time_low' => str_pad($components[0], 8, '0', STR_PAD_LEFT),
'time_mid' => str_pad($components[1], 4, '0', STR_PAD_LEFT),
'time_hi_and_version' => str_pad($components[2], 4, '0', STR_PAD_LEFT),
'clock_seq_hi_and_reserved' => str_pad(substr($components[3], 0, 2), 2, '0', STR_PAD_LEFT),
'clock_seq_low' => str_pad(substr($components[3], 2), 2, '0', STR_PAD_LEFT),
'node' => str_pad($components[4], 12, '0', STR_PAD_LEFT)
);
}
}

0 comments on commit 6a575eb

Please sign in to comment.