Skip to content

Commit 51f9fe1

Browse files
committed
Replace to emplace C++11 for code refactor and optimize inserts
Signed-off-by: Herman Semenov <[email protected]>
1 parent 92159c3 commit 51f9fe1

35 files changed

+174
-178
lines changed

media_common/agnostic/common/shared/media_factory.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,17 @@ class MediaFactory
6868
Iterator creator = creators.find(key);
6969
if (creator == creators.end())
7070
{
71-
std::pair<Iterator, bool> result =
72-
creators.insert(std::make_pair(key, Create<C>));
73-
sizes.insert(std::make_pair(key, (uint32_t)sizeof(C)));
74-
placecreators.insert(std::make_pair(key, PlaceCreate<C>));
71+
std::pair<Iterator, bool> result = creators.emplace(key, Create<C>);
72+
sizes.emplace(key, (uint32_t)sizeof(C));
73+
placecreators.emplace(key, PlaceCreate<C>);
7574
return result.second;
7675
}
7776
else
7877
{
7978
if (forceReplace)
8079
{
8180
creators.erase(creator);
82-
std::pair<Iterator, bool> result =
83-
creators.insert(std::make_pair(key, Create<C>));
81+
std::pair<Iterator, bool> result = creators.emplace(key, Create<C>);
8482
return result.second;
8583
}
8684
return true; //If it is registered, do nothing then return true.

media_driver/agnostic/common/codec/hal/codechal_kernel_base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ MOS_STATUS CodechalKernelBase::CreateKernelState(
146146
CODECHAL_ENCODE_CHK_NULL_RETURN(m_kernelBinary);
147147

148148
CODECHAL_ENCODE_CHK_NULL_RETURN((*kernelState) = MOS_New(MHW_KERNEL_STATE));
149-
m_kernelStatePool.insert(std::make_pair(kernelIndex, *kernelState));
149+
m_kernelStatePool.emplace(kernelIndex, *kernelState);
150150

151151
CODECHAL_KERNEL_HEADER kernelHeader = {};
152152
uint32_t kernelSize = 0;
@@ -319,7 +319,7 @@ MOS_STATUS CodechalKernelBase::AllocateSurface(PMOS_ALLOC_GFXRES_PARAMS param, P
319319
{
320320
CODECHAL_ENCODE_CHK_NULL_RETURN(param);
321321
CODECHAL_ENCODE_CHK_NULL_RETURN(surface);
322-
m_surfacePool.insert(std::make_pair(surfaceId, surface));
322+
m_surfacePool.emplace(surfaceId, surface);
323323

324324
CODECHAL_ENCODE_CHK_STATUS_RETURN(
325325
m_osInterface->pfnAllocateResource(

media_driver/agnostic/common/os/mos_util_user_interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ MOS_STATUS MosUtilUserInterface::AddEntry(const uint32_t keyId, PMOS_USER_FEATUR
3636

3737
if (result == m_userFeatureKeyMap.end())
3838
{
39-
m_userFeatureKeyMap.insert(std::make_pair(keyId, userFeatureKey));
39+
m_userFeatureKeyMap.emplace(keyId, userFeatureKey);
4040
}
4141
else
4242
{
4343
MOS_OS_NORMALMESSAGE("User feature key already exist, replacing the old one.");
4444
m_userFeatureKeyMap.erase(keyId);
45-
m_userFeatureKeyMap.insert(std::make_pair(keyId, userFeatureKey));
45+
m_userFeatureKeyMap.emplace(keyId, userFeatureKey);
4646
m_mosMutex.Unlock();
4747
return MOS_STATUS_SUCCESS;
4848
}

media_driver/linux/common/ddi/media_ddi_factory.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ class MediaDdiFactoryNoArg
154154
template <class C>
155155
static bool RegisterCodec(const KeyType &key)
156156
{
157-
std::pair<iterator, bool> result =
158-
GetCreators().insert(std::make_pair(key, create<C>));
157+
std::pair<iterator, bool> result = GetCreators().emplace(key, create<C>);
159158

160159
return result.second;
161160
}

media_softlet/agnostic/common/codec/hal/dec/shared/packet/decode_sub_packet_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ MOS_STATUS DecodeSubPacketManager::Register(uint32_t packetId, DecodeSubPacket&
4848
auto iter = m_subPacketList.find(packetId);
4949
DECODE_CHK_COND(iter != m_subPacketList.end(), "Failed to register sub packet %d", packetId);
5050

51-
m_subPacketList.insert(std::make_pair(packetId, &subPacket));
51+
m_subPacketList.emplace(packetId, &subPacket);
5252
return MOS_STATUS_SUCCESS;
5353
}
5454

media_softlet/agnostic/common/codec/hal/dec/shared/pipeline/decode_sub_pipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ MOS_STATUS DecodeSubPipeline::RegisterPacket(uint32_t packetId, MediaPacket& pac
7272
auto iter = m_packetList.find(packetId);
7373
if (iter == m_packetList.end())
7474
{
75-
m_packetList.insert(std::make_pair(packetId, &packet));
75+
m_packetList.emplace(packetId, &packet);
7676
}
7777

7878
return MOS_STATUS_SUCCESS;

media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_recycle_resource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ MOS_STATUS RecycleResource::RegisterResource(
8484
return MOS_STATUS_CLIENT_AR_NO_SPACE;
8585
}
8686

87-
m_resourceQueues.insert(std::make_pair(id, que));
87+
m_resourceQueues.emplace(id, que);
8888

8989
return MOS_STATUS_SUCCESS;
9090
}

media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_tracked_buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ MOS_STATUS TrackedBuffer::RegisterParam(BufferType type, MOS_ALLOC_GFXRES_PARAMS
6666
auto iter = m_allocParams.find(type);
6767
if (iter == m_allocParams.end())
6868
{
69-
m_allocParams.insert(std::make_pair(type, param));
69+
m_allocParams.emplace(type, param);
7070
}
7171
else
7272
{
@@ -279,7 +279,7 @@ std::shared_ptr<BufferQueue> TrackedBuffer::GetBufferQueue(BufferType type)
279279

280280
auto alloc = std::make_shared<BufferQueue>(m_allocator, param->second, m_maxSlotCnt);
281281
alloc->SetResourceType(resType);
282-
m_bufferQueue.insert(std::make_pair(type, alloc));
282+
m_bufferQueue.emplace(type, alloc);
283283
return alloc;
284284
}
285285
else

media_softlet/agnostic/common/media_interfaces/skuwa_factory.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ class DeviceInfoFactory
6060
//!
6161
static bool RegisterDevice(KeyType key, Type value)
6262
{
63-
std::pair<iterator, bool> result =
64-
GetCreators().insert(std::make_pair(key, value));
63+
std::pair<iterator, bool> result = GetCreators().emplace(key, value);
6564

6665
return result.second;
6766
}

media_softlet/agnostic/common/os/mos_oca_rtlog_mgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ MOS_STATUS MosOcaRTLogMgr::RegisterRes(OsContextNext *osDriverContext, MOS_OCA_R
103103
MOS_OS_CHK_STATUS_RETURN(status);
104104
}
105105
s_ocaMutex.Lock();
106-
m_resMap.insert(std::make_pair(osDriverContext, *resInterface));
106+
m_resMap.emplace(osDriverContext, *resInterface);
107107
s_ocaMutex.Unlock();
108108
osDriverContext->SetRtLogRes(resInterface->ocaRTLogResource);
109109
return MOS_STATUS_SUCCESS;

0 commit comments

Comments
 (0)