@@ -54,7 +54,7 @@ bool Enforcer::m_enforce(const std::string& matcher, Scope scope) {
5454
5555 if (ok) {
5656 for (auto [assertion_name, assertion] : m_model->m [" g" ].assertion_map ) {
57- std::shared_ptr<RoleManager> rm = assertion->rm ;
57+ std::shared_ptr<RoleManager>& rm = assertion->rm ;
5858
5959 int char_count = static_cast <int >(std::count (assertion->value .begin (), assertion->value .end (), ' _' ));
6060 size_t index = exp_string.find (assertion_name + " (" );
@@ -197,7 +197,7 @@ Enforcer ::Enforcer(const std::string& model_path, std::shared_ptr<Adapter> adap
197197 * @param m the model.
198198 * @param adapter the adapter.
199199 */
200- Enforcer::Enforcer (std::shared_ptr<Model> m, std::shared_ptr<Adapter> adapter)
200+ Enforcer::Enforcer (const std::shared_ptr<Model>& m, std::shared_ptr<Adapter> adapter)
201201 : m_adapter(adapter), m_watcher(nullptr ), m_model(m) {
202202 m_model->PrintModel ();
203203
@@ -212,7 +212,7 @@ Enforcer::Enforcer(std::shared_ptr<Model> m, std::shared_ptr<Adapter> adapter)
212212 *
213213 * @param m the model.
214214 */
215- Enforcer ::Enforcer (std::shared_ptr<Model> m): Enforcer(m, NULL ) {
215+ Enforcer::Enforcer (const std::shared_ptr<Model>& m) : Enforcer(m, NULL ) {
216216}
217217
218218/* *
@@ -244,15 +244,15 @@ void Enforcer::InitWithFile(const std::string& model_path, const std::string& po
244244
245245// InitWithAdapter initializes an enforcer with a database adapter.
246246void Enforcer::InitWithAdapter (const std::string& model_path, std::shared_ptr<Adapter> adapter) {
247- std::shared_ptr<Model> m = std::shared_ptr< Model>( Model ::NewModelFromFile (model_path) );
247+ std::shared_ptr<Model> m = Model::NewModelFromFile (model_path);
248248
249249 this ->InitWithModelAndAdapter (m, adapter);
250250
251251 m_model_path = model_path;
252252}
253253
254254// InitWithModelAndAdapter initializes an enforcer with a model and a database adapter.
255- void Enforcer::InitWithModelAndAdapter (std::shared_ptr<Model> m, std::shared_ptr<Adapter> adapter) {
255+ void Enforcer::InitWithModelAndAdapter (const std::shared_ptr<Model>& m, std::shared_ptr<Adapter> adapter) {
256256 m_adapter = adapter;
257257
258258 m_model = m;
@@ -281,7 +281,7 @@ void Enforcer::Initialize() {
281281// Because the policy is attached to a model, so the policy is invalidated and needs
282282// to be reloaded by calling LoadPolicy().
283283void Enforcer::LoadModel () {
284- m_model = std::shared_ptr< Model>( Model ::NewModelFromFile (m_model_path) );
284+ m_model = Model::NewModelFromFile (m_model_path);
285285
286286 m_model->PrintModel ();
287287 m_func_map.LoadFunctionMap ();
@@ -295,7 +295,7 @@ std::shared_ptr<Model> Enforcer::GetModel() {
295295}
296296
297297// SetModel sets the current model.
298- void Enforcer::SetModel (std::shared_ptr<Model> m) {
298+ void Enforcer::SetModel (const std::shared_ptr<Model>& m) {
299299 m_model = m;
300300 m_func_map.LoadFunctionMap ();
301301
@@ -327,7 +327,7 @@ std::shared_ptr<RoleManager> Enforcer ::GetRoleManager() {
327327}
328328
329329// SetRoleManager sets the current role manager.
330- void Enforcer::SetRoleManager (std::shared_ptr<RoleManager> rm) {
330+ void Enforcer::SetRoleManager (std::shared_ptr<RoleManager>& rm) {
331331 this ->rm = rm;
332332}
333333
@@ -344,7 +344,7 @@ void Enforcer::ClearPolicy() {
344344// LoadPolicy reloads the policy from file/database.
345345void Enforcer::LoadPolicy () {
346346 this ->ClearPolicy ();
347- m_adapter->LoadPolicy (m_model. get () );
347+ m_adapter->LoadPolicy (m_model);
348348 m_model->PrintPolicy ();
349349
350350 if (m_auto_build_role_links) {
@@ -381,12 +381,12 @@ void Enforcer::SavePolicy() {
381381 if (this ->IsFiltered ())
382382 throw CasbinEnforcerException (" cannot save a filtered policy" );
383383
384- m_adapter->SavePolicy (m_model. get () );
384+ m_adapter->SavePolicy (m_model);
385385
386386 if (m_watcher != NULL ){
387387 if (IsInstanceOf<WatcherEx>(m_watcher.get ())) {
388388 auto watcher = dynamic_cast <WatcherEx*>(m_watcher.get ());
389- watcher->UpdateForSavePolicy (m_model. get () );
389+ watcher->UpdateForSavePolicy (m_model);
390390 }
391391 else
392392 return m_watcher->Update ();
0 commit comments