From: Somnath Roy Date: Mon, 1 Feb 2016 19:35:26 +0000 (-0500) Subject: Use make_shared while creating shared_ptr X-Git-Tag: v10.1.0~276^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=331e90f450265891c68790bec2f82d39e0d096af;p=ceph.git Use make_shared while creating shared_ptr make_shared() will get rid of one extra 'new' call during shared_ptr creation.It is also 20-30% faster than creating shared_ptr directly by 'new' call. Signed-off-by: Somnath Roy --- diff --git a/src/include/encoding.h b/src/include/encoding.h index 3ba53274bd2a..a5a93a0996b7 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -429,7 +429,7 @@ inline void decode(std::list >& ls, bufferlist::iterator& p) decode(n, p); ls.clear(); while (n--) { - ceph::shared_ptr v(new T); + ceph::shared_ptr v(std::make_shared()); decode(*v, p); ls.push_back(v); } @@ -595,7 +595,7 @@ inline void decode(std::vector >& v, bufferlist::iterator& p decode(n, p); v.resize(n); for (__u32 i=0; i(); decode(*v[i], p); } } diff --git a/src/kv/KeyValueDB.h b/src/kv/KeyValueDB.h index f20b79909702..c7a83a253230 100644 --- a/src/kv/KeyValueDB.h +++ b/src/kv/KeyValueDB.h @@ -247,9 +247,7 @@ public: } Iterator get_iterator(const std::string &prefix) { - return ceph::shared_ptr( - new IteratorImpl(prefix, get_iterator()) - ); + return std::make_shared(prefix, get_iterator()); } WholeSpaceIterator get_snapshot_iterator() { @@ -257,9 +255,7 @@ public: } Iterator get_snapshot_iterator(const std::string &prefix) { - return ceph::shared_ptr( - new IteratorImpl(prefix, get_snapshot_iterator()) - ); + return std::make_shared(prefix, get_snapshot_iterator()); } virtual uint64_t get_estimated_size(std::map &extra) = 0; diff --git a/src/kv/KineticStore.h b/src/kv/KineticStore.h index c2be802dfab1..496cb4c0b9e2 100644 --- a/src/kv/KineticStore.h +++ b/src/kv/KineticStore.h @@ -95,8 +95,7 @@ public: }; KeyValueDB::Transaction get_transaction() { - return ceph::shared_ptr< KineticTransactionImpl >( - new KineticTransactionImpl(this)); + return std::make_shared(this); } int submit_transaction(KeyValueDB::Transaction t); @@ -148,8 +147,7 @@ public: protected: WholeSpaceIterator _get_iterator() { - return ceph::shared_ptr( - new KineticWholeSpaceIteratorImpl(kinetic_conn.get())); + return std::make_shared(kinetic_conn.get()); } // TODO: remove snapshots from interface diff --git a/src/kv/LevelDBStore.h b/src/kv/LevelDBStore.h index 8260f8b351ec..766ed1960e9e 100644 --- a/src/kv/LevelDBStore.h +++ b/src/kv/LevelDBStore.h @@ -199,8 +199,7 @@ public: }; KeyValueDB::Transaction get_transaction() { - return ceph::shared_ptr< LevelDBTransactionImpl >( - new LevelDBTransactionImpl(this)); + return std::make_shared(this); } int submit_transaction(KeyValueDB::Transaction t); @@ -402,11 +401,8 @@ err: protected: WholeSpaceIterator _get_iterator() { - return ceph::shared_ptr( - new LevelDBWholeSpaceIteratorImpl( - db->NewIterator(leveldb::ReadOptions()) - ) - ); + return std::make_shared( + db->NewIterator(leveldb::ReadOptions())); } WholeSpaceIterator _get_snapshot_iterator() { @@ -416,10 +412,9 @@ protected: snapshot = db->GetSnapshot(); options.snapshot = snapshot; - return ceph::shared_ptr( - new LevelDBSnapshotIteratorImpl(db.get(), snapshot, - db->NewIterator(options)) - ); + return std::make_shared( + db.get(), snapshot, + db->NewIterator(options)); } }; diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 923537cb9275..d8751cc4435b 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -657,11 +657,8 @@ string RocksDBStore::past_prefix(const string &prefix) RocksDBStore::WholeSpaceIterator RocksDBStore::_get_iterator() { - return std::shared_ptr( - new RocksDBWholeSpaceIteratorImpl( - db->NewIterator(rocksdb::ReadOptions()) - ) - ); + return std::make_shared( + db->NewIterator(rocksdb::ReadOptions())); } RocksDBStore::WholeSpaceIterator RocksDBStore::_get_snapshot_iterator() @@ -672,10 +669,8 @@ RocksDBStore::WholeSpaceIterator RocksDBStore::_get_snapshot_iterator() snapshot = db->GetSnapshot(); options.snapshot = snapshot; - return std::shared_ptr( - new RocksDBSnapshotIteratorImpl(db, snapshot, - db->NewIterator(options)) - ); + return std::make_shared( + db, snapshot, db->NewIterator(options)); } RocksDBStore::RocksDBSnapshotIteratorImpl::~RocksDBSnapshotIteratorImpl() diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 63cbc5ad6c2b..41508ba6cd10 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -157,8 +157,7 @@ public: }; KeyValueDB::Transaction get_transaction() { - return std::shared_ptr< RocksDBTransactionImpl >( - new RocksDBTransactionImpl(this)); + return std::make_shared(this); } int submit_transaction(KeyValueDB::Transaction t); diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index ba638bfad96c..f319e7656882 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -177,7 +177,7 @@ int ObjectStore::queue_transactions( Context *oncomplete, TrackedOpRef op = TrackedOpRef()) { - RunOnDeleteRef _complete(new RunOnDelete(oncomplete)); + RunOnDeleteRef _complete (std::make_shared(oncomplete)); Context *_onreadable = new Wrapper( onreadable, _complete); Context *_oncommit = new Wrapper( diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index b0b952452ae8..885922f19d94 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -579,7 +579,7 @@ public: } void register_on_complete(Context *c) { if (!c) return; - RunOnDeleteRef _complete(new RunOnDelete(c)); + RunOnDeleteRef _complete (std::make_shared(c)); register_on_applied(new ContainerContext(_complete)); register_on_commit(new ContainerContext(_complete)); } diff --git a/src/os/filestore/CollectionIndex.h b/src/os/filestore/CollectionIndex.h index 0d1fc30fcb36..942dc233e656 100644 --- a/src/os/filestore/CollectionIndex.h +++ b/src/os/filestore/CollectionIndex.h @@ -77,8 +77,8 @@ protected: /// Type of returned paths typedef ceph::shared_ptr IndexedPath; - static IndexedPath get_testing_path(string path, const coll_t& collection) { - return IndexedPath(new Path(path, collection)); + static IndexedPath get_testing_path(string path, coll_t collection) { + return std::make_shared(path, collection); } static const uint32_t FLAT_INDEX_TAG = 0; diff --git a/src/os/filestore/DBObjectMap.cc b/src/os/filestore/DBObjectMap.cc index 04340439c7a9..67e17bdb8c89 100644 --- a/src/os/filestore/DBObjectMap.cc +++ b/src/os/filestore/DBObjectMap.cc @@ -237,7 +237,7 @@ int DBObjectMap::DBObjectMapIteratorImpl::init() assert(0); return -EINVAL; } - parent_iter.reset(new DBObjectMapIteratorImpl(map, parent)); + parent_iter = std::make_shared(map, parent); } key_iter = map->db->get_iterator(map->user_prefix(header)); assert(key_iter); diff --git a/src/os/filestore/DBObjectMap.h b/src/os/filestore/DBObjectMap.h index 400c54a1f386..de68f3c3b699 100644 --- a/src/os/filestore/DBObjectMap.h +++ b/src/os/filestore/DBObjectMap.h @@ -413,7 +413,7 @@ private: typedef ceph::shared_ptr DBObjectMapIterator; DBObjectMapIterator _get_iterator(Header header) { - return DBObjectMapIterator(new DBObjectMapIteratorImpl(this, header)); + return std::make_shared(this, header); } /// sys diff --git a/src/os/filestore/LFNIndex.cc b/src/os/filestore/LFNIndex.cc index 4cc09c32cc12..4962d6a269b9 100644 --- a/src/os/filestore/LFNIndex.cc +++ b/src/os/filestore/LFNIndex.cc @@ -124,7 +124,7 @@ int LFNIndex::lookup(const ghobject_t &oid, if (r < 0) goto out; string full_path = get_full_path(path, short_name); - *out_path = IndexedPath(new Path(full_path, this)); + *out_path = std::make_shared(full_path, this); r = 0; ); } diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 7345d535301b..9f7354b5efd5 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2725,8 +2725,8 @@ void OSD::recursive_remove_collection(ObjectStore *store, spg_t pgid, coll_t tmp coll_t(), make_snapmapper_oid()); - ceph::shared_ptr osr( - new ObjectStore::Sequencer("rm")); + ceph::shared_ptr osr (std::make_shared< + ObjectStore::Sequencer>("rm")); ObjectStore::Transaction t; SnapMapper mapper(&driver, 0, 0, 0, pgid.shard); @@ -5318,8 +5318,8 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& cmd, buffe cmd_getval(cct, cmdmap, "object_size", osize, (int64_t)0); cmd_getval(cct, cmdmap, "object_num", onum, (int64_t)0); - ceph::shared_ptr osr( - new ObjectStore::Sequencer("bench")); + ceph::shared_ptr osr (std::make_shared< + ObjectStore::Sequencer>("bench")); uint32_t duration = g_conf->osd_bench_duration; diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 6694e27b3bb9..46b51f36a102 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -270,15 +270,15 @@ private: flags(0), num_osd(0), num_up_osd(0), num_in_osd(0), max_osd(0), - osd_addrs(new addrs_s), - pg_temp(new map >), - primary_temp(new map), - osd_uuid(new vector), + osd_addrs(std::make_shared()), + pg_temp(std::make_shared>>()), + primary_temp(std::make_shared>()), + osd_uuid(std::make_shared>()), cluster_snapshot_epoch(0), new_blacklist_entries(false), cached_up_osd_features(0), crc_defined(false), crc(0), - crush(new CrushWrapper) { + crush(std::make_shared()) { memset(&fsid, 0, sizeof(fsid)); } diff --git a/src/osd/PG.cc b/src/osd/PG.cc index ac5075aaa731..068e3b79e4be 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -2016,7 +2016,7 @@ void PG::all_activated_and_committed() queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), AllReplicasActivated()))); @@ -2719,8 +2719,8 @@ void PG::upgrade(ObjectStore *store) dirty_big_info = true; write_if_dirty(t); - ceph::shared_ptr osr( - new ObjectStore::Sequencer("upgrade")); + ceph::shared_ptr osr (std::make_shared< + ObjectStore::Sequencer>("upgrade")); int r = store->apply_transaction(osr.get(), std::move(t)); if (r != 0) { derr << __func__ << ": apply_transaction returned " @@ -4461,7 +4461,7 @@ void PG::scrub_finish() if (has_error) { queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), DoRecovery()))); @@ -4770,8 +4770,8 @@ void PG::start_flush(ObjectStore::Transaction *t, list *on_safe) { // flush in progress ops - FlushStateRef flush_trigger( - new FlushState(this, get_osdmap()->get_epoch())); + FlushStateRef flush_trigger (std::make_shared( + this, get_osdmap()->get_epoch())); t->nop(); flushes_in_progress++; on_applied->push_back(new ContainerContext(flush_trigger)); @@ -5391,7 +5391,7 @@ void PG::queue_null(epoch_t msg_epoch, { dout(10) << "null" << dendl; queue_peering_event( - CephPeeringEvtRef(new CephPeeringEvt(msg_epoch, query_epoch, + CephPeeringEvtRef(std::make_shared(msg_epoch, query_epoch, NullEvt()))); } @@ -5399,7 +5399,7 @@ void PG::queue_flushed(epoch_t e) { dout(10) << "flushed" << dendl; queue_peering_event( - CephPeeringEvtRef(new CephPeeringEvt(e, e, + CephPeeringEvtRef(std::make_shared(e, e, FlushedEvt()))); } @@ -5409,7 +5409,7 @@ void PG::queue_query(epoch_t msg_epoch, { dout(10) << "handle_query " << q << " from replica " << from << dendl; queue_peering_event( - CephPeeringEvtRef(new CephPeeringEvt(msg_epoch, query_epoch, + CephPeeringEvtRef(std::make_shared(msg_epoch, query_epoch, MQuery(from, q, query_epoch)))); } diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index bef96d68747f..32595dcf44f3 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -1151,7 +1151,7 @@ void ReplicatedBackend::sub_op_modify_impl(OpRequestRef op) op->mark_started(); - RepModifyRef rm(new RepModify); + RepModifyRef rm(std::make_shared()); rm->op = op; rm->ackerosd = ackerosd; rm->last_complete = get_info().last_complete; diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 3cd4bd95aa99..15a24b9cb0cb 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -2389,7 +2389,7 @@ void ReplicatedPG::do_proxy_read(OpRequestRef op) dout(10) << __func__ << " Start proxy read for " << *m << dendl; - ProxyReadOpRef prdop(new ProxyReadOp(op, soid, m->ops)); + ProxyReadOpRef prdop(std::make_shared(op, soid, m->ops)); ObjectOperation obj_op; obj_op.dup(prdop->ops); @@ -2574,7 +2574,7 @@ void ReplicatedPG::do_proxy_write(OpRequestRef op, const hobject_t& missing_oid) unsigned flags = CEPH_OSD_FLAG_IGNORE_CACHE | CEPH_OSD_FLAG_IGNORE_OVERLAY; dout(10) << __func__ << " Start proxy write for " << *m << dendl; - ProxyWriteOpRef pwop(new ProxyWriteOp(op, soid, m->ops, m->get_reqid())); + ProxyWriteOpRef pwop(std::make_shared(op, soid, m->ops, m->get_reqid())); pwop->ctx = new OpContext(op, m->get_reqid(), pwop->ops, this); pwop->mtime = m->get_mtime(); @@ -3075,7 +3075,7 @@ void ReplicatedPG::do_scan( << ratio << ", which exceeds " << full_ratio << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), BackfillTooFull()))); @@ -3153,7 +3153,7 @@ void ReplicatedPG::do_backfill(OpRequestRef op) osd->send_message_osd_cluster(reply, m->get_connection()); queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), RecoveryDone()))); @@ -6957,7 +6957,7 @@ void ReplicatedPG::start_copy(CopyCallback *cb, ObjectContextRef obc, cancel_copy(cop, false); } - CopyOpRef cop(new CopyOp(cb, obc, src, oloc, version, flags, + CopyOpRef cop(std::make_shared(cb, obc, src, oloc, version, flags, mirror_snapset, src_obj_fadvise_flags, dest_obj_fadvise_flags)); copy_ops[dest] = cop; @@ -7810,7 +7810,7 @@ int ReplicatedPG::start_flush( NULL /* no callback, we'll rely on the ordering w.r.t the next op */); } - FlushOpRef fop(new FlushOp); + FlushOpRef fop(std::make_shared()); fop->obc = obc; fop->flushed_version = oi.user_version; fop->blocking = blocking; @@ -9659,7 +9659,7 @@ void ReplicatedPG::on_activate() dout(10) << "activate not all replicas are up-to-date, queueing recovery" << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), DoRecovery()))); @@ -9667,7 +9667,7 @@ void ReplicatedPG::on_activate() dout(10) << "activate queueing backfill" << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), RequestBackfill()))); @@ -9675,7 +9675,7 @@ void ReplicatedPG::on_activate() dout(10) << "activate all replicas clean, no recovery" << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), AllReplicasRecovered()))); @@ -10027,7 +10027,7 @@ bool ReplicatedPG::start_recovery_ops( backfill_reserving = true; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), RequestBackfill()))); @@ -10080,7 +10080,7 @@ bool ReplicatedPG::start_recovery_ops( dout(10) << "recovery done, queuing backfill" << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), RequestBackfill()))); @@ -10088,7 +10088,7 @@ bool ReplicatedPG::start_recovery_ops( dout(10) << "recovery done, no backfill" << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), AllReplicasRecovered()))); @@ -10098,7 +10098,7 @@ bool ReplicatedPG::start_recovery_ops( dout(10) << "recovery done, backfill done" << dendl; queue_peering_event( CephPeeringEvtRef( - new CephPeeringEvt( + std::make_shared( get_osdmap()->get_epoch(), get_osdmap()->get_epoch(), Backfilled()))); diff --git a/src/osd/ReplicatedPG.h b/src/osd/ReplicatedPG.h index 0ee87a7f5e66..00d1826af23e 100644 --- a/src/osd/ReplicatedPG.h +++ b/src/osd/ReplicatedPG.h @@ -167,7 +167,7 @@ public: results.mirror_snapset = mirror_snapset; } }; - typedef boost::shared_ptr CopyOpRef; + typedef ceph::shared_ptr CopyOpRef; /** * The CopyCallback class defines an interface for completions to the @@ -212,7 +212,7 @@ public: user_version(0), data_offset(0), canceled(false) { } }; - typedef boost::shared_ptr ProxyReadOpRef; + typedef ceph::shared_ptr ProxyReadOpRef; struct ProxyWriteOp { OpContext *ctx; @@ -234,7 +234,7 @@ public: sent_ack(false), canceled(false), reqid(_reqid) { } }; - typedef boost::shared_ptr ProxyWriteOpRef; + typedef ceph::shared_ptr ProxyWriteOpRef; struct FlushOp { ObjectContextRef obc; ///< obc we are flushing @@ -253,7 +253,7 @@ public: on_flush(NULL) {} ~FlushOp() { assert(!on_flush); } }; - typedef boost::shared_ptr FlushOpRef; + typedef ceph::shared_ptr FlushOpRef; boost::scoped_ptr pgbackend; PGBackend *get_pgbackend() {