From 5dc1356d5cab95c9d6aac9eedaadd0fd2d2904d3 Mon Sep 17 00:00:00 2001 From: JCDenton Date: Wed, 7 Dec 2022 03:57:01 +0300 Subject: [PATCH] Optimize inserts C++11 and code simplify --- lib/include/srsran/rlc/rlc.h | 1 - lib/src/rlc/rlc.cc | 6 +++--- srsepc/src/mme/mme_gtpc.cc | 4 ++-- srsepc/src/mme/s1ap.cc | 12 ++++++------ srsepc/src/spgw/gtpc.cc | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/include/srsran/rlc/rlc.h b/lib/include/srsran/rlc/rlc.h index cfaa3b830..348901b1f 100644 --- a/lib/include/srsran/rlc/rlc.h +++ b/lib/include/srsran/rlc/rlc.h @@ -97,7 +97,6 @@ private: srsran::timer_handler* timers = nullptr; typedef std::map > rlc_map_t; - typedef std::pair > rlc_map_pair_t; rlc_map_t rlc_array, rlc_array_mrb; pthread_rwlock_t rwlock; diff --git a/lib/src/rlc/rlc.cc b/lib/src/rlc/rlc.cc index bbad52a52..f67302858 100644 --- a/lib/src/rlc/rlc.cc +++ b/lib/src/rlc/rlc.cc @@ -444,7 +444,7 @@ int rlc::add_bearer(uint32_t lcid, const rlc_config_t& cnfg) rlc_entity->set_bsr_callback(bsr_callback); - if (not rlc_array.insert(rlc_map_pair_t(lcid, std::move(rlc_entity))).second) { + if (not rlc_array.emplace(lcid, std::move(rlc_entity)).second) { logger.error("Error inserting RLC entity in to array."); return SRSRAN_ERROR; } @@ -467,7 +467,7 @@ int rlc::add_bearer_mrb(uint32_t lcid) } rlc_entity->set_bsr_callback(bsr_callback); if (rlc_array_mrb.count(lcid) == 0) { - if (not rlc_array_mrb.insert(rlc_map_pair_t(lcid, std::move(rlc_entity))).second) { + if (not rlc_array_mrb.emplace(lcid, std::move(rlc_entity)).second) { logger.error("Error inserting RLC entity in to array."); return SRSRAN_ERROR; } @@ -517,7 +517,7 @@ void rlc::change_lcid(uint32_t old_lcid, uint32_t new_lcid) // insert old rlc entity into new LCID rlc_map_t::iterator it = rlc_array.find(old_lcid); std::unique_ptr rlc_entity = std::move(it->second); - if (not rlc_array.insert(rlc_map_pair_t(new_lcid, std::move(rlc_entity))).second) { + if (not rlc_array.emplace(new_lcid, std::move(rlc_entity)).second) { logger.error("Error inserting RLC entity into array."); return; } diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index e5157f474..6f82b789a 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -174,13 +174,13 @@ bool mme_gtpc::send_create_session_request(uint64_t imsi) } // Save RX Control TEID - m_mme_ctr_teid_to_imsi.insert(std::pair(cs_req->sender_f_teid.teid, imsi)); + m_mme_ctr_teid_to_imsi.emplace(cs_req->sender_f_teid.teid, imsi); // Save GTP-C context gtpc_ctx_t gtpc_ctx; std::memset(>pc_ctx, 0, sizeof(gtpc_ctx_t)); gtpc_ctx.mme_ctr_fteid = cs_req->sender_f_teid; - m_imsi_to_gtpc_ctx.insert(std::pair(imsi, gtpc_ctx)); + m_imsi_to_gtpc_ctx.emplace(imsi, gtpc_ctx); // Send msg to SPGW send_s11_pdu(cs_req_pdu); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 9917c6583..6462867b9 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -308,9 +308,9 @@ void s1ap::add_new_enb_ctx(const enb_ctx_t& enb_ctx, const struct sctp_sndrcvinf std::set ue_set; enb_ctx_t* enb_ptr = new enb_ctx_t; *enb_ptr = enb_ctx; - m_active_enbs.insert(std::pair(enb_ptr->enb_id, enb_ptr)); - m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); - m_enb_assoc_to_ue_ids.insert(std::pair >(enb_sri->sinfo_assoc_id, ue_set)); + m_active_enbs.emplace(enb_ptr->enb_id, enb_ptr); + m_sctp_to_enb_id.emplace(enb_sri->sinfo_assoc_id, enb_ptr->enb_id); + m_enb_assoc_to_ue_ids.emplace(enb_sri->sinfo_assoc_id, ue_set); } enb_ctx_t* s1ap::find_enb_ctx(uint16_t enb_id) @@ -362,7 +362,7 @@ bool s1ap::add_nas_ctx_to_imsi_map(nas* nas_ctx) return false; } } - m_imsi_to_nas_ctx.insert(std::pair(nas_ctx->m_emm_ctx.imsi, nas_ctx)); + m_imsi_to_nas_ctx.emplace(nas_ctx->m_emm_ctx.imsi, nas_ctx); m_logger.debug("Saved UE context corresponding to IMSI %015" PRIu64 "", nas_ctx->m_emm_ctx.imsi); return true; } @@ -385,7 +385,7 @@ bool s1ap::add_nas_ctx_to_mme_ue_s1ap_id_map(nas* nas_ctx) return false; } } - m_mme_ue_s1ap_id_to_nas_ctx.insert(std::pair(nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_ctx)); + m_mme_ue_s1ap_id_to_nas_ctx.emplace(nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_ctx); m_logger.debug("Saved UE context corresponding to MME UE S1AP Id %d", nas_ctx->m_ecm_ctx.mme_ue_s1ap_id); return true; } @@ -551,7 +551,7 @@ uint32_t s1ap::allocate_m_tmsi(uint64_t imsi) uint32_t m_tmsi = m_next_m_tmsi; m_next_m_tmsi = (m_next_m_tmsi + 1) % UINT32_MAX; - m_tmsi_to_imsi.insert(std::pair(m_tmsi, imsi)); + m_tmsi_to_imsi.emplace(m_tmsi, imsi); m_logger.debug("Allocated M-TMSI 0x%x to IMSI %015" PRIu64 ",", m_tmsi, imsi); return m_tmsi; } diff --git a/srsepc/src/spgw/gtpc.cc b/srsepc/src/spgw/gtpc.cc index 9e3eac3b3..fbfc5a5bd 100644 --- a/srsepc/src/spgw/gtpc.cc +++ b/srsepc/src/spgw/gtpc.cc @@ -455,8 +455,8 @@ spgw_tunnel_ctx_t* spgw::gtpc::create_gtpc_ctx(const struct srsran::gtpc_create_ tunnel_ctx->dw_ctrl_fteid.ipv4 = cs_req.sender_f_teid.ipv4; std::memset(&tunnel_ctx->dw_user_fteid, 0, sizeof(srsran::gtp_fteid_t)); - m_teid_to_tunnel_ctx.insert(std::pair(spgw_uplink_ctrl_teid, tunnel_ctx)); - m_imsi_to_ctr_teid.insert(std::pair(cs_req.imsi, spgw_uplink_ctrl_teid)); + m_teid_to_tunnel_ctx.emplace(spgw_uplink_ctrl_teid, tunnel_ctx); + m_imsi_to_ctr_teid.emplace(cs_req.imsi, spgw_uplink_ctrl_teid); return tunnel_ctx; }