@@ -112,14 +112,14 @@ std::u16string toString(double value)
112
112
return text;
113
113
}
114
114
115
- std::u16string toString (Object* object )
115
+ std::u16string toString (const std::shared_ptr<Imp>& pimpl )
116
116
{
117
- if (!object )
117
+ if (!pimpl )
118
118
return u" null" ;
119
- Any result = object ->message_ (0 , 0 , Object::STRINGIFY_, 0 );
119
+ Any result{ pimpl ->message_ (0 , 0 , Object::STRINGIFY_, 0 ) } ;
120
120
if (result.isString ())
121
121
return result.toString ();
122
- return u" " ;
122
+ return std::u16string () ;
123
123
}
124
124
125
125
double toNumber (const std::u16string& value)
@@ -225,33 +225,27 @@ double toNumber(const std::u16string& value)
225
225
226
226
} // namespace
227
227
228
- bool Any::isString () const
229
- {
230
- return (type == Dynamic) && vtable->getType () == typeid (std::u16string);
231
- }
232
-
233
228
std::u16string Any::toString () const
234
229
{
235
230
switch (type) {
236
231
case Bool:
237
- return heap. i32 ? u" true" : u" false" ;
232
+ return i32 ? u" true" : u" false" ;
238
233
case Int32:
239
- return ::toString (" %d" , heap. i32 );
234
+ return ::toString (" %d" , i32);
240
235
case Uint32:
241
- return ::toString (" %u" , heap. u32 );
236
+ return ::toString (" %u" , u32);
242
237
case Int64:
243
- return ::toString (" %lld" , heap. i64 );
238
+ return ::toString (" %lld" , i64);
244
239
case Uint64:
245
- return ::toString (" %llu" , heap. u64 );
240
+ return ::toString (" %llu" , u64);
246
241
case Float32 :
247
- return ::toString (heap. f32 );
242
+ return ::toString (f32);
248
243
case Float64 :
249
- return ::toString (heap.f64 );
250
- case Dynamic:
251
- if (vtable->getType () == typeid (std::u16string))
252
- return *reinterpret_cast <const std::u16string*>(&heap);
253
- if (vtable->getType () == typeid (Object))
254
- return ::toString (const_cast <Object*>(reinterpret_cast <const Object*>(&heap)));
244
+ return ::toString (f64);
245
+ case String:
246
+ return string;
247
+ case Shared:
248
+ return ::toString (pimpl);
255
249
break ;
256
250
default :
257
251
break ;
@@ -269,20 +263,19 @@ double Any::toNumber() const
269
263
return NAN;
270
264
case Bool:
271
265
case Int32:
272
- return heap. i32 ;
266
+ return i32;
273
267
case Uint32:
274
- return heap. u32 ;
268
+ return u32;
275
269
case Int64:
276
- return heap. i64 ;
270
+ return i64;
277
271
case Uint64:
278
- return heap. u64 ;
272
+ return u64;
279
273
case Float32 :
280
- return heap. f32 ;
274
+ return f32;
281
275
case Float64 :
282
- return heap.f64 ;
283
- case Dynamic:
284
- if (vtable->getType () == typeid (std::u16string))
285
- return ::toNumber (*reinterpret_cast <const std::u16string*>(&heap));
276
+ return f64;
277
+ case String:
278
+ return ::toNumber (string);
286
279
break ;
287
280
default :
288
281
break ;
@@ -298,43 +291,42 @@ unsigned int Any::toArrayIndex() const
298
291
case Bool:
299
292
break ;
300
293
case Int32:
301
- if (0 <= heap. i32 )
302
- return heap. i32 ;
294
+ if (0 <= i32)
295
+ return i32;
303
296
break ;
304
297
case Uint32:
305
- return heap. u32 ;
298
+ return u32;
306
299
case Int64:
307
- if (0 <= heap. i64 && heap. i64 < UINT_MAX)
308
- return heap. i64 ;
300
+ if (0 <= i64 && i64 < UINT_MAX)
301
+ return i64;
309
302
case Uint64:
310
- if (heap. u64 < UINT_MAX)
311
- return heap. u64 ;
303
+ if (u64 < UINT_MAX)
304
+ return u64;
312
305
break ;
313
306
case Float32 :
314
- if (0 .0f <= heap. f32 ) {
315
- float f = floorf (heap. f32 );
316
- if (f == heap. f32 && f < UINT_MAX)
317
- return static_cast <unsigned int >(heap. f32 );
307
+ if (0 .0f <= f32) {
308
+ float f = floorf (f32);
309
+ if (f == f32 && f < UINT_MAX)
310
+ return static_cast <unsigned int >(f32);
318
311
}
319
312
break ;
320
313
case Float64 :
321
- if (0.0 <= heap. f64 ) {
322
- double f = floor (heap. f64 );
323
- if (f == heap. f64 && f < UINT_MAX)
324
- return static_cast <unsigned int >(heap. f64 );
314
+ if (0.0 <= f64) {
315
+ double f = floor (f64);
316
+ if (f == f64 && f < UINT_MAX)
317
+ return static_cast <unsigned int >(f64);
325
318
}
326
319
break ;
327
320
break ;
328
- case Dynamic:
329
- if (vtable->getType () == typeid (std::u16string)) {
330
- double v = ::toNumber (*reinterpret_cast <const std::u16string*>(&heap));
331
- if (0.0 <= v) {
332
- double f = floor (v);
333
- if (f == v && f < UINT_MAX && ::toString (f) == *reinterpret_cast <const std::u16string*>(&heap))
334
- return static_cast <unsigned int >(f);
335
- }
321
+ case String: {
322
+ double v = ::toNumber (string);
323
+ if (0.0 <= v) {
324
+ double f = floor (v);
325
+ if (f == v && f < UINT_MAX && ::toString (f) == string)
326
+ return static_cast <unsigned int >(f);
336
327
}
337
328
break ;
329
+ }
338
330
default :
339
331
break ;
340
332
}
@@ -350,36 +342,22 @@ bool Any::toBoolean() const
350
342
switch (type) {
351
343
case Bool:
352
344
case Int32:
353
- return heap. i32 ;
345
+ return i32;
354
346
case Uint32:
355
- return heap. u32 ;
347
+ return u32;
356
348
case Int64:
357
- return heap. i64 ;
349
+ return i64;
358
350
case Uint64:
359
- return heap. u64 ;
351
+ return u64;
360
352
case Float32 :
361
- return heap. f32 && !isnan (heap. f32 );
353
+ return f32 && !isnan (f32);
362
354
case Float64 :
363
- return heap.f64 && !isnan (heap.f64 );
364
- case Dynamic:
365
- if (vtable->getType () == typeid (std::u16string))
366
- return (*reinterpret_cast <const std::u16string*>(&heap)).length ();
367
- return true ;
355
+ return f64 && !isnan (f64);
356
+ case String:
357
+ return string.length ();
368
358
break ;
369
359
default :
370
360
break ;
371
361
}
372
362
return false ;
373
363
}
374
-
375
- bool Any::isObject () const
376
- {
377
- return (type == Dynamic) && vtable->getType () == typeid (Object);
378
- }
379
-
380
- Object* Any::toObject () const
381
- {
382
- if (isObject ())
383
- return const_cast <Object*>(reinterpret_cast <const Object*>(&heap));
384
- return 0 ;
385
- }
0 commit comments