From 8b80373f178b4bdba515d65f88461c1ff9217a57 Mon Sep 17 00:00:00 2001 From: bill fumerola Date: Mon, 10 Jun 2013 11:25:49 -0700 Subject: [PATCH] expose Vector->reserve(size) to php space example usage: genv() takes a Vector of Awaitable and creates a Vector of WaitHandles. resize() requires a default value, reserve allows us to hint proper allocation. --- hphp/runtime/ext/ext_collections.cpp | 15 +++++++++++++++ hphp/runtime/ext/ext_collections.h | 1 + hphp/system/idl/collections.idl.json | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/hphp/runtime/ext/ext_collections.cpp b/hphp/runtime/ext/ext_collections.cpp index 7e25d4427..cc7d54cd1 100644 --- a/hphp/runtime/ext/ext_collections.cpp +++ b/hphp/runtime/ext/ext_collections.cpp @@ -256,6 +256,21 @@ void c_Vector::t_resize(CVarRef sz, CVarRef value) { resize(intSz, val); } +void c_Vector::t_reserve(CVarRef sz) { + if (!sz.isInteger()) { + Object e(SystemLib::AllocInvalidArgumentExceptionObject( + "Parameter sz must be a non-negative integer")); + throw e; + } + int64_t intSz = sz.toInt64(); + if (intSz < 0) { + Object e(SystemLib::AllocInvalidArgumentExceptionObject( + "Parameter sz must be a non-negative integer")); + throw e; + } + reserve(intSz); +} + Object c_Vector::t_clear() { ++m_version; uint sz = m_size; diff --git a/hphp/runtime/ext/ext_collections.h b/hphp/runtime/ext/ext_collections.h index 2cd693855..45518089d 100644 --- a/hphp/runtime/ext/ext_collections.h +++ b/hphp/runtime/ext/ext_collections.h @@ -46,6 +46,7 @@ class c_Vector : public ExtObjectDataFlags