GeezerVison is showing github.com — sqlite: cache the SQLTagStore constructor template · nodejs/node@1dd9dbe
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/env_properties.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 456 | 456 | V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \ | 457 | 457 | V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \ | 458 | 458 | V(sqlite_session_constructor_template, v8::FunctionTemplate) \ | | 459 | + V(sqlite_tag_store_constructor_template, v8::FunctionTemplate) \ | 459 | 460 | V(srv_record_template, v8::DictionaryTemplate) \ | 460 | 461 | V(streambaseoutputstream_constructor_template, v8::ObjectTemplate) \ | 461 | 462 | V(tcp_constructor_template, v8::FunctionTemplate) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_sqlite.cc +21-18Lines changed: 21 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4353,24 +4353,27 @@ static inline void SetSideEffectFreeGetter( | 4353 | 4353 | SQLTagStore::~SQLTagStore() {} | 4354 | 4354 |
| 4355 | 4355 | Local<FunctionTemplate> SQLTagStore::GetConstructorTemplate(Environment* env) { | 4356 | | - Isolate* isolate = env->isolate(); | 4357 | | - Local<FunctionTemplate> tmpl = | 4358 | | - NewFunctionTemplate(isolate, IllegalConstructor); | 4359 | | - tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore")); | 4360 | | - tmpl->InstanceTemplate()->SetInternalFieldCount( | 4361 | | - SQLTagStore::kInternalFieldCount); | 4362 | | - SetProtoMethod(isolate, tmpl, "get", Get); | 4363 | | - SetProtoMethod(isolate, tmpl, "all", All); | 4364 | | - SetProtoMethod(isolate, tmpl, "iterate", Iterate); | 4365 | | - SetProtoMethod(isolate, tmpl, "run", Run); | 4366 | | - SetProtoMethod(isolate, tmpl, "clear", Clear); | 4367 | | - SetSideEffectFreeGetter(isolate, | 4368 | | - tmpl, | 4369 | | - FIXED_ONE_BYTE_STRING(isolate, "capacity"), | 4370 | | - CapacityGetter); | 4371 | | - SetSideEffectFreeGetter( | 4372 | | - isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter); | 4373 | | - SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter); | | 4356 | + Local<FunctionTemplate> tmpl = env->sqlite_tag_store_constructor_template(); | | 4357 | + if (tmpl.IsEmpty()) { | | 4358 | + Isolate* isolate = env->isolate(); | | 4359 | + tmpl = NewFunctionTemplate(isolate, IllegalConstructor); | | 4360 | + tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore")); | | 4361 | + tmpl->InstanceTemplate()->SetInternalFieldCount( | | 4362 | + SQLTagStore::kInternalFieldCount); | | 4363 | + SetProtoMethod(isolate, tmpl, "get", Get); | | 4364 | + SetProtoMethod(isolate, tmpl, "all", All); | | 4365 | + SetProtoMethod(isolate, tmpl, "iterate", Iterate); | | 4366 | + SetProtoMethod(isolate, tmpl, "run", Run); | | 4367 | + SetProtoMethod(isolate, tmpl, "clear", Clear); | | 4368 | + SetSideEffectFreeGetter(isolate, | | 4369 | + tmpl, | | 4370 | + FIXED_ONE_BYTE_STRING(isolate, "capacity"), | | 4371 | + CapacityGetter); | | 4372 | + SetSideEffectFreeGetter( | | 4373 | + isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter); | | 4374 | + SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter); | | 4375 | + env->set_sqlite_tag_store_constructor_template(tmpl); | | 4376 | + } | 4374 | 4377 | return tmpl; | 4375 | 4378 | } | 4376 | 4379 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-sqlite-template-tag.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -295,6 +295,12 @@ test('sql.db returns the associated Database instance', () => { | 295 | 295 | assert.strictEqual(sql.db, db); | 296 | 296 | }); | 297 | 297 |
| | 298 | +test('tag stores share a prototype', () => { | | 299 | + const other = new Database(':memory:').createTagStore(); | | 300 | + assert.strictEqual(Object.getPrototypeOf(other), Object.getPrototypeOf(sql)); | | 301 | + assert.strictEqual(other.constructor, sql.constructor); | | 302 | +}); | | 303 | + | 298 | 304 | test('sql error messages are descriptive', () => { | 299 | 305 | assert.strictEqual(sql.run`INSERT INTO foo (text) VALUES (${'test'})`.changes, 1); | 300 | 306 |
| |
|