Skip to content

Commit 028b861

Browse files
committed
Get speed1.js working
1 parent 0bd4f5e commit 028b861

20 files changed

+178
-169
lines changed

js.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ struct Value {
191191

192192
// convert dbaddr_t to void *
193193

194-
#define js_addr(val) (void *)((val).marshaled ? js_dbaddr(val, NULL) : (val).addr)
195194
extern void *js_dbaddr(value_t val, document_t *doc);
196195
value_t js_handle(value_t hndl, int hndlType);
197196

js_bson.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void build_move(uint8_t type, build_t **document, build_t **doclast, uint32_t *d
268268
build_append(doclen, document, doclast, &type, 1);
269269

270270
if (name.type == vt_string) {
271-
string_t *str = js_addr(name);
271+
string_t *str = js_dbaddr(name, NULL);
272272
build_append(doclen, document, doclast, str->val, str->len);
273273
}
274274

@@ -330,7 +330,7 @@ Status bson_response (FILE *file, uint32_t request, uint32_t response, uint32_t
330330
// find next value in parent object or array
331331

332332
if (item->type == vt_array) {
333-
dbarray_t *dbaval = js_addr(*item);
333+
dbarray_t *dbaval = js_dbaddr(*item, NULL);
334334
value_t *values = item->marshaled ? dbaval->valueArray : item->aval->valuePtr;
335335
uint32_t max = item->marshaled ? dbaval->cnt : vec_cnt(values);
336336

@@ -344,7 +344,7 @@ Status bson_response (FILE *file, uint32_t request, uint32_t response, uint32_t
344344
continue;
345345
}
346346
} else if (item->type == vt_object) {
347-
dbobject_t *dboval = js_addr(*item);
347+
dbobject_t *dboval = js_dbaddr(*item, NULL);
348348
pair_t *pairs = item->marshaled ? dboval->pairs : item->oval->pairsPtr;
349349
uint32_t cnt = item->marshaled ? dboval->cnt : vec_cnt(pairs);
350350

@@ -364,14 +364,14 @@ Status bson_response (FILE *file, uint32_t request, uint32_t response, uint32_t
364364

365365
switch (obj[depth].type) {
366366
case vt_string: {
367-
string_t *str = js_addr(obj[depth]);
367+
string_t *str = js_dbaddr(obj[depth], NULL);
368368
uint32_t len = str->len + 1;
369369
doctype = 0x02;
370370

371371
build_append(doclen + depth, document + depth, doclast + depth, &doctype, 1);
372372

373373
if (name[depth].type == vt_string) {
374-
string_t *namestr = js_addr(name[depth]);
374+
string_t *namestr = js_dbaddr(name[depth], NULL);
375375
build_append(doclen + depth, document + depth, doclast + depth, namestr->val, namestr->len);
376376
}
377377

@@ -388,7 +388,7 @@ Status bson_response (FILE *file, uint32_t request, uint32_t response, uint32_t
388388
build_append(doclen + depth, document + depth, doclast + depth, &doctype, 1);
389389

390390
if (depth && name[depth].type == vt_string) {
391-
string_t *str = js_addr(name[depth]);
391+
string_t *str = js_dbaddr(name[depth], NULL);
392392
build_append(doclen + depth, document + depth, doclast + depth, str->val, str->len);
393393
}
394394

@@ -402,7 +402,7 @@ Status bson_response (FILE *file, uint32_t request, uint32_t response, uint32_t
402402
build_append(doclen + depth, document + depth, doclast + depth, &doctype, 1);
403403

404404
if (depth && name[depth].type == vt_string) {
405-
string_t *str = js_addr(name[depth]);
405+
string_t *str = js_dbaddr(name[depth], NULL);
406406
build_append(doclen + depth, document + depth, doclast + depth, str->val, str->len);
407407
}
408408

js_date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ value_t newDate(value_t *args) {
8181
}
8282

8383
if (args[0].type == vt_string) {
84-
string_t *str = js_addr(args[0]);
84+
string_t *str = js_dbaddr(args[0], NULL);
8585
result.date = get_date(str->val); // rely on zero terminator
8686
return result;
8787
}

js_db.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ value_t ans;
3838

3939
void processOptions(Params *params, value_t options) {
4040
uint32_t size = sizeof(Params) * (MaxParam + 1);
41-
dbarray_t *dbaval = js_addr(options);
41+
dbarray_t *dbaval = js_dbaddr(options, NULL);
4242
uint32_t cnt, idx;
4343
value_t *values;
4444

@@ -138,7 +138,7 @@ value_t js_openCatalog(uint32_t args, environment_t *env) {
138138
path = eval_arg(&args, env);
139139

140140
if (vt_string == path.type)
141-
pathstr = js_addr(path);
141+
pathstr = js_dbaddr(path, NULL);
142142
else {
143143
fprintf(stderr, "Error: openCatalog => expecting path:string => %s\n", strtype(path.type));
144144
return s.status = ERROR_script_internal, s;
@@ -147,7 +147,7 @@ value_t js_openCatalog(uint32_t args, environment_t *env) {
147147
name = eval_arg(&args, env);
148148

149149
if (vt_string == name.type)
150-
namestr = js_addr(name);
150+
namestr = js_dbaddr(name, NULL);
151151
else {
152152
fprintf(stderr, "Error: openCatalog => expecting name:string => %s\n", strtype(name.type));
153153
return s.status = ERROR_script_internal, s;
@@ -202,7 +202,7 @@ value_t js_openDatabase(uint32_t args, environment_t *env) {
202202
name = eval_arg (&args, env);
203203

204204
if (name.type == vt_string)
205-
namestr = js_addr(name);
205+
namestr = js_dbaddr(name, NULL);
206206
else {
207207
fprintf(stderr, "Error: openDatabase => expecting dbname:string => %s\n", strtype(name.type));
208208
return s.status = ERROR_script_internal, s;
@@ -256,7 +256,7 @@ value_t js_createIndex(uint32_t args, environment_t *env) {
256256
name = eval_arg (&args, env);
257257

258258
if (name.type == vt_string)
259-
namestr = js_addr(name);
259+
namestr = js_dbaddr(name, NULL);
260260
else {
261261
fprintf(stderr, "Error: createIndex => expecting name:string => %s\n", strtype(name.type));
262262
return s.status = ERROR_script_internal, s;
@@ -395,7 +395,7 @@ n", strtype(database.type));
395395
name = eval_arg(&args, env);
396396

397397
if (name.type == vt_string)
398-
namestr = js_addr(name);
398+
namestr = js_dbaddr(name, NULL);
399399
else {
400400
fprintf(stderr, "Error: openDocStore => expecting name:string => %s\n", strtype(name.type));
401401
return s.status = ERROR_script_internal, s;

js_db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Document {
2020
uint32_t refCnt[1];
2121
ObjId docId;
2222
DbAddr ourAddr;
23-
value_t value[1]; // clone document value
23+
value_t value[1]; // cloned document value
2424
uint32_t docLen;
2525
uint8_t base[];
2626
};

js_dbcursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ value_t fcnCursorPos(value_t *args, value_t thisVal, environment_t *env) {
8282

8383
op = conv2Int(args[0], false);
8484
key = conv2Str(args[1], false, false);
85-
str = js_addr(key);
85+
str = js_dbaddr(key, NULL);
8686

8787
val.status = dbFindKey(dbCursor, docMap, str->val, str->len, op.nval);
8888

js_dbdoc.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
#include "js_dbindex.h"
77
#include <stddef.h>
88

9-
void *js_dbaddr(value_t val, document_t *doc) {
10-
document_t *document;
9+
void *js_dbaddr(value_t val, document_t * doc) {
10+
if (val.marshaled && val.document)
11+
doc = val.document;
1112

12-
if ((document = val.addr))
13-
return document->base + val.offset;
14-
else if (doc)
15-
return doc->base + val.offset;
13+
if( val.marshaled )
14+
return doc->base + val.offset;
1615

17-
fprintf(stderr, "Not document item: %s\n", strtype(val.type));
16+
if ((vt_document == val.type))
17+
return val.document->base + val.offset;
18+
else
19+
return val.addr;
20+
21+
fprintf(stderr, "Not document item: %s\n", strtype(val.type));
1822
exit(1);
1923
}
2024

@@ -27,9 +31,6 @@ value_t makeDocument(ObjId docId, DbMap *map) {
2731
val.document = document;
2832
val.refcount = true;
2933

30-
if (document->value->marshaled)
31-
val.offset = sizeof(document_t);
32-
3334
atomicAdd32(document->refCnt, 1);
3435
return val;
3536
}
@@ -65,8 +66,11 @@ value_t convDocObject(value_t obj) {
6566
// retrieve document object
6667

6768
value_t getDocObject(value_t doc) {
68-
document_t *document = doc.addr;
69-
return *document->value;
69+
value_t ans;
70+
71+
ans.bits = doc.document->value->bits;
72+
ans.document = doc.document;
73+
return ans;
7074
}
7175

7276
// clone marshaled array
@@ -138,7 +142,7 @@ value_t cloneObject(value_t obj, value_t doc) {
138142
value_t fcnStoreAppend(value_t *args, value_t thisVal, environment_t *env) {
139143
document_t *prevDoc;
140144
Handle *docHndl;
141-
value_t resp, s;
145+
value_t resp, s, v;
142146
DbAddr *addr;
143147
value_t hndl;
144148
uint32_t idx;
@@ -161,7 +165,7 @@ value_t fcnStoreAppend(value_t *args, value_t thisVal, environment_t *env) {
161165
// multiple document/value case
162166

163167
if (args[0].type == vt_array) {
164-
dbarray_t *dbaval = js_addr(args[0]);
168+
dbarray_t *dbaval = js_dbaddr(args[0], NULL);
165169
value_t *values = args[0].marshaled ? dbaval->valueArray : args[0].aval->valuePtr;
166170
uint32_t cnt = args[0].marshaled ? dbaval->cnt : vec_cnt(values);
167171
resp = newArray(array_value, cnt);
@@ -176,16 +180,21 @@ value_t fcnStoreAppend(value_t *args, value_t thisVal, environment_t *env) {
176180
break;
177181
}
178182

179-
respval->valuePtr[idx] = makeDocument(*docId, map);
183+
v.bits = vt_docId;
184+
v.idBits = docId->bits;
185+
respval->valuePtr[idx] = v;
180186
}
181187
} else {
182188
docId->bits = 0;
183189
prevDoc = appendDoc(docHndl, args[0], docId);
184190

191+
v.bits = vt_docId;
192+
v.idBits = docId->bits;
193+
185194
if (jsError(prevDoc))
186195
s.status = (Status)prevDoc;
187196
else
188-
resp = makeDocument(*docId, map);
197+
resp = v;
189198
}
190199

191200
if (!s.status)
@@ -215,25 +224,22 @@ value_t fcnDocIdToString(value_t *args, value_t thisVal, environment_t *env) {
215224
// display a document
216225

217226
value_t fcnDocToString(value_t *args, value_t thisVal, environment_t *env) {
218-
document_t *document = thisVal.addr;
219-
return conv2Str(*document->value, true, false);
227+
return conv2Str(*thisVal.document->value, true, false);
220228
}
221229

222230
// return base value for a document version (usually a vt_document object)
223231

224232
value_t fcnDocValueOf(value_t *args, value_t thisVal, environment_t *env) {
225-
document_t *document = thisVal.addr;
226-
return *document->value;
233+
return *thisVal.document->value;
227234
}
228235

229236
// return size of a document version
230237

231238
value_t fcnDocSize(value_t *args, value_t thisVal, environment_t *env) {
232-
document_t *document = thisVal.addr;
233239
value_t v;
234240

235241
v.bits = vt_int;
236-
v.nval = document->docLen;
242+
v.nval = thisVal.document->docLen;
237243
return v;
238244
}
239245

@@ -269,11 +275,10 @@ value_t fcnDocUpdate(value_t *args, value_t thisVal, environment_t *env) {
269275
// return the docId of a version
270276

271277
value_t propDocDocId(value_t val, bool lval) {
272-
document_t *document = val.addr;
273278
value_t v;
274279

275280
v.bits = vt_docId;
276-
v.idBits = document->docId.bits;
281+
v.idBits = val.document->docId.bits;
277282
return v;
278283
}
279284

js_dbindex.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int keyFld (value_t src, KeySpec *spec, KeyValue *keyValue, bool binaryFlds) {
187187

188188
default:
189189
val = conv2Str(src, false, false);
190-
str = js_addr(val);
190+
str = js_dbaddr(val, NULL);
191191

192192
len = str->len;
193193

@@ -248,7 +248,7 @@ uint32_t eval_option(uint8_t *opt, int amt) {
248248
}
249249

250250
uint32_t key_options(value_t option) {
251-
string_t *str = js_addr(option);
251+
string_t *str = js_dbaddr(option, NULL);
252252
uint8_t *opt = str->val;
253253
uint32_t len = str->len;
254254
uint32_t val = 0, amt;
@@ -284,7 +284,7 @@ uint32_t key_options(value_t option) {
284284
// compile keys into permanent spot in the database
285285

286286
DbAddr compileKeys(DbHandle hndl[1], value_t keySpec) {
287-
dbobject_t *dboval = js_addr(keySpec);
287+
dbobject_t *dboval = js_dbaddr(keySpec, NULL);
288288
pair_t *pairs = keySpec.marshaled ? dboval->pairs : keySpec.oval->pairsPtr;
289289
uint32_t cnt = keySpec.marshaled ? dboval->cnt : vec_cnt(pairs);
290290
uint32_t idx, off, fld;
@@ -308,7 +308,7 @@ DbAddr compileKeys(DbHandle hndl[1], value_t keySpec) {
308308

309309
for( idx = 0; idx < cnt; idx++) {
310310
size += sizeof(KeySpec) + sizeof(struct Field);
311-
str = js_addr(pairs[idx].name);
311+
str = js_dbaddr(pairs[idx].name, NULL);
312312

313313
// go through field name
314314

@@ -330,7 +330,7 @@ DbAddr compileKeys(DbHandle hndl[1], value_t keySpec) {
330330

331331
for (idx = 0; idx < cnt; idx++) {
332332
spec = (KeySpec *)(base + off);
333-
str = js_addr(pairs[idx].name);
333+
str = js_dbaddr(pairs[idx].name, NULL);
334334
off += sizeof(*spec);
335335

336336
memset (spec, 0, sizeof(*spec));
@@ -491,7 +491,7 @@ void buildKeys(Handle **idxHndls, uint16_t keyIdx, value_t rec, DbAddr *keys, Ob
491491
// handle multi-key spec
492492
493493
if (val.type == vt_array) {
494-
dbarray_t *dbaval = js_addr(val);
494+
dbarray_t *dbaval = js_dbaddr(val, NULL);
495495
KeyStack *item = &stack[depth];
496496
497497
item->values = val.marshaled ? dbaval->valueArray : val.aval->valuePtr;

0 commit comments

Comments
 (0)