File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -374,25 +374,22 @@ class atomadapter_indexing : public vector_indexing_suite<
374
374
static object
375
375
get_slice (Container& container, index_type from, index_type to)
376
376
{
377
+ // make sure slice is of a correct type and has a copy
378
+ // of any additional structure data.
377
379
StructureAdapterPtr rv = container.clone ();
378
380
AtomicStructureAdapterPtr rva;
379
381
rva = boost::static_pointer_cast<AtomicStructureAdapter>(rv);
380
- // short-circuit for long slices
381
- if ((to - from) > rva-> countSites () / 2 )
382
+ // handle index ranges for a valid and empty slice
383
+ if (from <= to )
382
384
{
383
385
rva->erase (rva->begin () + to, rva->end ());
384
386
rva->erase (rva->begin (), rva->begin () + from);
385
- return object (rv);
386
- }
387
- // otherwise save memory for short slices
388
- rva->clear ();
389
- rv = rva->clone ();
390
- rva = boost::static_pointer_cast<AtomicStructureAdapter>(rv);
391
- if (from <= to)
392
- {
393
- rva->assign (container.begin () + from, container.begin () + to);
394
387
}
395
- return object (rv);
388
+ else rva->clear ();
389
+ // save memory by making a new copy for short slices
390
+ const bool longslice = ((to - from) > rva->countSites () / 2 );
391
+ object pyrv (longslice ? rv : rv->clone ());
392
+ return pyrv;
396
393
}
397
394
398
395
You can’t perform that action at this time.
0 commit comments