Performance improvement to generated+supporting PHP (#5080)

By avoiding redundant alignment+alloc checks (startVector does prep) and virtual calls
(by making the class final) in inner loops.
This commit is contained in:
Peter Dillinger
2018-12-20 16:10:20 -08:00
committed by Wouter van Oortmerssen
parent cb99116aca
commit 87704e987e
5 changed files with 35 additions and 28 deletions

View File

@@ -21,7 +21,7 @@
namespace Google\FlatBuffers;
class FlatbufferBuilder
final class FlatbufferBuilder
{
/**
* Internal ByteBuffer for the FlatBuffer data.
@@ -278,6 +278,15 @@ class FlatbufferBuilder
{
$this->bb->putDouble($this->space -= 8, $x);
}
/**
* @param $off
*/
public function putOffset($off)
{
$new_off = $this->offset() - $off + Constants::SIZEOF_INT;
$this->putInt($new_off);
}
/// @endcond
/**
@@ -562,9 +571,7 @@ class FlatbufferBuilder
if ($off > $this->offset()) {
throw new \Exception("");
}
$off = $this->offset() - $off + Constants::SIZEOF_INT;
$this->putInt($off);
$this->putOffset($off);
}
/// @cond FLATBUFFERS_INTERNAL