Commits

JanKanis committed 71233ee

Make event_t.arguments into a vector instead of an auto_ptr<vector>.

Yay for less indirection and less code! The resulting event_t structure is two pointers larger, but cuts out an indirection and allocation.

Comments (0)

Files changed (4)

         mark_changed_exported();
 
         event_t ev = event_t::variable_event(name);
-        ev.arguments.reset(new wcstring_list_t());
-        ev.arguments->push_back(L"VARIABLE");
-        ev.arguments->push_back(str);
-        ev.arguments->push_back(name);
+        ev.arguments.push_back(L"VARIABLE");
+        ev.arguments.push_back(str);
+        ev.arguments.push_back(name);
         event_fire(&ev);
-        ev.arguments.reset(NULL);
     }
 
     if (name)
     if (!is_universal)
     {
         event_t ev = event_t::variable_event(key);
-        ev.arguments.reset(new wcstring_list_t);
-        ev.arguments->push_back(L"VARIABLE");
-        ev.arguments->push_back(L"SET");
-        ev.arguments->push_back(key);
+        ev.arguments.push_back(L"VARIABLE");
+        ev.arguments.push_back(L"SET");
+        ev.arguments.push_back(key);
 
         //  debug( 1, L"env_set: fire events on variable %ls", key );
         event_fire(&ev);
         //  debug( 1, L"env_set: return from event firing" );
-        ev.arguments.reset(NULL);
     }
 
     react_to_variable_change(key);
         if (try_remove(first_node, key.c_str(), var_mode))
         {
             event_t ev = event_t::variable_event(key);
-            ev.arguments.reset(new wcstring_list_t);
-            ev.arguments->push_back(L"VARIABLE");
-            ev.arguments->push_back(L"ERASE");
-            ev.arguments->push_back(key);
+            ev.arguments.push_back(L"VARIABLE");
+            ev.arguments.push_back(L"ERASE");
+            ev.arguments.push_back(key);
 
             event_fire(&ev);
 
-            ev.arguments.reset(NULL);
             erased = 1;
         }
     }
 }
 
 
-/**
-   Create an identical copy of an event. Use deep copying, i.e. make
-   duplicates of any strings used as well.
-*/
-static event_t *event_copy(const event_t *event, int copy_arguments)
-{
-    event_t *e = new event_t(*event);
-
-    e->arguments.reset(new wcstring_list_t);
-    if (copy_arguments && event->arguments.get() != NULL)
-    {
-        *(e->arguments) = *(event->arguments);
-    }
-
-    return e;
-}
 
 /**
    Test if specified event is blocked
     event_t *e;
 
     CHECK(event,);
-		if(debug_level >= 3)
-				debug(3, "register: %ls\n", event_type_str(event).c_str());
-		
-    e = event_copy(event, 0);
+    if(debug_level >= 3)
+        debug(3, "register: %ls\n", event_type_str(event).c_str());
+
+    e = new event_t(*event);
 
     if (e->type == EVENT_SIGNAL)
     {
         */
         wcstring buffer = criterion->function_name;
 
-        if (event->arguments.get())
+        if (! event->arguments.empty())
         {
-            for (j=0; j< event->arguments->size(); j++)
+            for (j=0; j < event->arguments.size(); j++)
             {
-                wcstring arg_esc = escape_string(event->arguments->at(j), 1);
+                wcstring arg_esc = escape_string(event->arguments.at(j), 1);
                 buffer += L" ";
                 buffer += arg_esc;
             }
             event_t *e = blocked.at(i);
             if (event_is_blocked(e))
             {
-                new_blocked.push_back(e);
+                new_blocked.push_back(new event_t(*e));
             }
             else
             {
           Set up
         */
         event_t e = event_t::signal_event(0);
-        e.arguments.reset(new wcstring_list_t(1)); //one element
         lst = &sig_list[1-active_list];
 
         if (lst->overflow)
         for (int i=0; i < lst->count; i++)
         {
             e.param1.signal = lst->signal[i];
-            e.arguments->at(0) = sig2wcs(e.param1.signal);
+            e.arguments.at(0) = sig2wcs(e.param1.signal);
             if (event_is_blocked(&e))
             {
-                blocked.push_back(event_copy(&e, 1));
+                blocked.push_back(new event_t(e));
             }
             else
             {
             }
         }
 
-        e.arguments.reset(NULL);
-
     }
 }
 
         {
             if (event_is_blocked(event))
             {
-                blocked.push_back(event_copy(event, 1));
+                blocked.push_back(new event_t(*event));
             }
             else
             {
     event_t ev(EVENT_GENERIC);
     ev.str_param1 = name;
     if (args)
-        ev.arguments.reset(new wcstring_list_t(*args));
+        ev.arguments = *args;
     event_fire(&ev);
 }
 
     event.str_param1 = str;
     return event;
 }
-
-event_t::event_t(const event_t &x) :
-    type(x.type),
-    param1(x.param1),
-    str_param1(x.str_param1),
-    function_name(x.function_name)
-{
-    const wcstring_list_t *ptr = x.arguments.get();
-    if (ptr)
-        arguments.reset(new wcstring_list_t(*ptr));
-}
+ 
        event_fire. In all other situations, the value of this variable
        is ignored.
     */
-    std::auto_ptr<wcstring_list_t> arguments;
+    wcstring_list_t arguments;
 
     event_t(int t) : type(t), param1(), str_param1(), function_name(), arguments() { }
 
-    /** Copy constructor */
-    event_t(const event_t &x);
+    /** default copy constructor */
+		//event_t(const event_t &x); 
+
 
     static event_t signal_event(int sig);
     static event_t variable_event(const wcstring &str);
 void proc_init()
 {
     proc_push_interactive(0);
-    event.arguments.reset(new wcstring_list_t);
 }
 
 
 
 void proc_destroy()
 {
-    event.arguments.reset(NULL);
     job_list_t &jobs = parser_t::principal_parser().job_list();
     while (! jobs.empty())
     {
     event.type=type;
     event.param1.pid = pid;
 
-    event.arguments->push_back(msg);
-    event.arguments->push_back(to_string<int>(pid));
-    event.arguments->push_back(to_string<int>(status));
+    event.arguments.push_back(msg);
+    event.arguments.push_back(to_string<int>(pid));
+    event.arguments.push_back(to_string<int>(status));
     event_fire(&event);
-    event.arguments->resize(0);
+    event.arguments.resize(0);
 }
 
 int job_reap(bool interactive)