@@ -54,8 +54,8 @@ int QirArray::Release()
5454 return rc;
5555}
5656
57- QirArray::QirArray (TItemCount qubits_count )
58- : count(qubits_count )
57+ QirArray::QirArray (TItemCount qubitsCount )
58+ : count(qubitsCount )
5959 , itemSizeInBytes((TItemSize)sizeof(void *))
6060 , ownsQubits(true )
6161 , refCount(1 )
@@ -81,25 +81,25 @@ QirArray::QirArray(TItemCount qubits_count)
8181 }
8282}
8383
84- QirArray::QirArray (TItemCount count_items , TItemSize item_size_bytes , TDimCount dimCount, TDimContainer&& dimSizes)
85- : count(count_items )
84+ QirArray::QirArray (TItemCount countItems , TItemSize itemSizeBytes , TDimCount dimCount, TDimContainer&& dimSizes)
85+ : count(countItems )
8686
8787 // Each array item needs to be properly aligned. Let's align them by correcting the `itemSizeInBytes`.
8888 , itemSizeInBytes(
89- ((item_size_bytes == 1 ) || (item_size_bytes == 2 ) || (item_size_bytes == 4 ) ||
90- ((item_size_bytes % sizeof (size_t )) == 0) // For built-in types or multiples of architecture alignment
89+ ((itemSizeBytes == 1 ) || (itemSizeBytes == 2 ) || (itemSizeBytes == 4 ) ||
90+ ((itemSizeBytes % sizeof (size_t )) == 0) // For built-in types or multiples of architecture alignment
9191 )
92- ? item_size_bytes // leave their natural alignment.
93- // Other types align on the architecture boundary `sizeof(size_t)`:
94- // 4 bytes on 32-bit arch, 8 on 64-bit arch.
95- : item_size_bytes + sizeof(size_t ) - (item_size_bytes % sizeof (size_t )))
92+ ? itemSizeBytes // leave their natural alignment.
93+ // Other types align on the architecture boundary `sizeof(size_t)`:
94+ // 4 bytes on 32-bit arch, 8 on 64-bit arch.
95+ : itemSizeBytes + sizeof(size_t ) - (itemSizeBytes % sizeof (size_t )))
9696
9797 , dimensions(dimCount)
9898 , dimensionSizes(std::move(dimSizes))
9999 , ownsQubits(false )
100100 , refCount(1 )
101101{
102- assert (item_size_bytes != 0 );
102+ assert (itemSizeBytes != 0 );
103103 assert (dimCount > 0 );
104104
105105 if (GlobalContext () != nullptr )
@@ -112,18 +112,18 @@ QirArray::QirArray(TItemCount count_items, TItemSize item_size_bytes, TDimCount
112112 assert (this ->dimensionSizes .empty () || this ->dimensionSizes [0 ] == this ->count );
113113 if (this ->dimensionSizes .empty ())
114114 {
115- this ->dimensionSizes .push_back (count_items );
115+ this ->dimensionSizes .push_back (countItems );
116116 }
117117 }
118118
119119 assert (this ->count * (TBufSize)itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
120120 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
121- const TBufSize buffer_size = this ->count * itemSizeInBytes;
122- if (buffer_size > 0 )
121+ const TBufSize bufferSize = this ->count * itemSizeInBytes;
122+ if (bufferSize > 0 )
123123 {
124- this ->buffer = new char [buffer_size ];
125- assert (buffer_size <= std::numeric_limits<size_t >::max ());
126- memset (this ->buffer , 0 , (size_t )buffer_size );
124+ this ->buffer = new char [bufferSize ];
125+ assert (bufferSize <= std::numeric_limits<size_t >::max ());
126+ memset (this ->buffer , 0 , (size_t )bufferSize );
127127 }
128128 else
129129 {
@@ -178,26 +178,26 @@ void QirArray::Append(const QirArray* other)
178178
179179 assert ((TBufSize)(other->count ) * other->itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
180180 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
181- const TBufSize other_size = other->count * other->itemSizeInBytes ;
181+ const TBufSize otherSize = other->count * other->itemSizeInBytes ;
182182
183- if (other_size == 0 )
183+ if (otherSize == 0 )
184184 {
185185 return ;
186186 }
187187
188188 assert ((TBufSize)(this ->count ) * this ->itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
189189 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
190- const TBufSize this_size = this ->count * this ->itemSizeInBytes ;
190+ const TBufSize thisSize = this ->count * this ->itemSizeInBytes ;
191191
192- char * new_buffer = new char [this_size + other_size ];
193- if (this_size )
192+ char * newBuffer = new char [thisSize + otherSize ];
193+ if (thisSize )
194194 {
195- memcpy (new_buffer , this ->buffer , this_size );
195+ memcpy (newBuffer , this ->buffer , thisSize );
196196 }
197- memcpy (&new_buffer[this_size ], other->buffer , other_size );
197+ memcpy (&newBuffer[thisSize ], other->buffer , otherSize );
198198
199199 delete[] this ->buffer ;
200- this ->buffer = new_buffer ;
200+ this ->buffer = newBuffer ;
201201 this ->count += other->count ;
202202 this ->dimensionSizes [0 ] = this ->count ;
203203}
@@ -279,11 +279,10 @@ extern "C"
279279 __quantum__rt__qubit_release_array (qa);
280280 }
281281
282- // TODO: Use `QirArray::TItemSize itemSizeInBytes, QirArray::TItemCount count_items` (breaking change):
283- QirArray* __quantum__rt__array_create_1d (int32_t itemSizeInBytes, int64_t count_items)
282+ QirArray* __quantum__rt__array_create_1d (int32_t itemSizeInBytes, int64_t countItems)
284283 {
285284 assert (itemSizeInBytes > 0 );
286- return new QirArray ((QirArray::TItemCount)count_items , (QirArray::TItemSize)itemSizeInBytes);
285+ return new QirArray ((QirArray::TItemCount)countItems , (QirArray::TItemSize)itemSizeInBytes);
287286 }
288287
289288 // Bucketing of addref/release is non-standard so for now we'll keep the more traditional addref/release semantics
@@ -560,6 +559,10 @@ extern "C"
560559 const QirArray::TItemCount sliceItemsCount = std::accumulate (
561560 sliceDims.begin (), sliceDims.end (), (QirArray::TItemCount)1 , std::multiplies<QirArray::TItemCount>());
562561 QirArray* slice = new QirArray (sliceItemsCount, itemSizeInBytes, dimensions, std::move (sliceDims));
562+ if (nullptr == slice->buffer )
563+ {
564+ return slice;
565+ }
563566 const QirArray::TItemCount singleIndexRunCount = RunCount (array->dimensionSizes , (QirArray::TDimCount)dim);
564567 const QirArray::TItemCount rowCount = singleIndexRunCount * array->dimensionSizes [(size_t )dim];
565568
@@ -636,13 +639,18 @@ extern "C"
636639 const QirArray::TItemCount projectItemsCount = std::accumulate (
637640 projectDims.begin (), projectDims.end (), (QirArray::TItemCount)1 , std::multiplies<QirArray::TItemCount>());
638641 QirArray* project = new QirArray (projectItemsCount, itemSizeInBytes, dimensions - 1 , std::move (projectDims));
642+ if (nullptr == project->buffer )
643+ {
644+ return project;
645+ }
639646
640647 const QirArray::TItemCount singleIndexRunCount = RunCount (array->dimensionSizes , (QirArray::TDimCount)dim);
641648 const QirArray::TItemCount rowCount = singleIndexRunCount * array->dimensionSizes [(size_t )dim];
642649
643650 assert ((QirArray::TBufSize)singleIndexRunCount * itemSizeInBytes <
644651 std::numeric_limits<QirArray::TBufSize>::max ());
645652 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
653+
646654 const QirArray::TBufSize chunkSize = singleIndexRunCount * itemSizeInBytes;
647655
648656 QirArray::TItemCount dst = 0 ;
0 commit comments