diff options
| author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2019-01-23 03:36:36 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2019-01-24 17:08:27 +0000 |
| commit | 9643b2fc2ee8fe82f689e3bfbdc3329a1421ec3d (patch) | |
| tree | 6fa48fa6c9721b921fd397944105d5072bebb6fb /src/debug | |
| parent | Remove unused svg-profile.h header file. (diff) | |
| download | inkscape-9643b2fc2ee8fe82f689e3bfbdc3329a1421ec3d.tar.gz inkscape-9643b2fc2ee8fe82f689e3bfbdc3329a1421ec3d.zip | |
Event: Make name and property name char const*.
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/event.h | 15 | ||||
| -rw-r--r-- | src/debug/logger.cpp | 8 | ||||
| -rw-r--r-- | src/debug/simple-event.h | 26 |
3 files changed, 18 insertions, 31 deletions
diff --git a/src/debug/event.h b/src/debug/event.h index e9fa5ae2e..de5cddd07 100644 --- a/src/debug/event.h +++ b/src/debug/event.h @@ -41,23 +41,22 @@ public: struct PropertyPair { public: PropertyPair() = default; - PropertyPair(Util::ptr_shared n, Util::ptr_shared v) - : name(n), value(v) {} PropertyPair(char const *n, Util::ptr_shared v) - : name(Util::share_string(n)), value(v) {} - PropertyPair(Util::ptr_shared n, char const *v) - : name(n), value(Util::share_string(v)) {} + : name(n), value(v) {} PropertyPair(char const *n, char const *v) - : name(Util::share_string(n)), + : name(n), value(Util::share_string(v)) {} - Util::ptr_shared name; + char const *name; Util::ptr_shared value; }; static Category category() { return OTHER; } - virtual Util::ptr_shared name() const=0; + // To reduce allocations, we assume the name here is always allocated statically and will never + // need to be deallocated. It would be nice to be able to assert that during the creation of + // the Event though. + virtual char const *name() const=0; virtual unsigned propertyCount() const=0; virtual PropertyPair property(unsigned property) const=0; diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp index 742ad6e58..13d79daa2 100644 --- a/src/debug/logger.cpp +++ b/src/debug/logger.cpp @@ -159,7 +159,7 @@ void Logger::init() { } void Logger::_start(Event const &event) { - Util::ptr_shared name=event.name(); + char const *name=event.name(); if (empty_tag) { log_stream << ">\n"; @@ -167,19 +167,19 @@ void Logger::_start(Event const &event) { write_indent(log_stream, tag_stack().size()); - log_stream << "<" << name.pointer(); + log_stream << "<" << name; unsigned property_count=event.propertyCount(); for ( unsigned i = 0 ; i < property_count ; i++ ) { Event::PropertyPair property=event.property(i); - log_stream << " " << property.name.pointer() << "=\""; + log_stream << " " << property.name << "=\""; write_escaped_value(log_stream, property.value); log_stream << "\""; } log_stream.flush(); - tag_stack().push_back(name); + tag_stack().push_back(Util::share_string(name)); empty_tag = true; event.generateChildEvents(); diff --git a/src/debug/simple-event.h b/src/debug/simple-event.h index 7dc706fe7..70bef77e9 100644 --- a/src/debug/simple-event.h +++ b/src/debug/simple-event.h @@ -27,15 +27,14 @@ namespace Debug { template <Event::Category C=Event::OTHER> class SimpleEvent : public Event { public: - explicit SimpleEvent(Util::ptr_shared name) : _name(name) {} - explicit SimpleEvent(char const *name) : _name(Util::share_string(name)) {} + explicit SimpleEvent(char const *name) : _name(name) {} // default copy // default assign static Category category() { return C; } - Util::ptr_shared name() const override { return _name; } + char const *name() const override { return _name; } unsigned propertyCount() const override { return _properties.size(); } PropertyPair property(unsigned property) const override { return _properties[property]; @@ -44,32 +43,21 @@ public: void generateChildEvents() const override {} protected: - void _addProperty(Util::ptr_shared name, - Util::ptr_shared value) - { - _properties.push_back(PropertyPair(name, value)); - } - void _addProperty(Util::ptr_shared name, char const *value) { - _addProperty(name, Util::share_string(value)); - } void _addProperty(char const *name, Util::ptr_shared value) { - _addProperty(Util::share_string(name), value); + _properties.push_back(PropertyPair(name, value)); } void _addProperty(char const *name, char const *value) { - _addProperty(Util::share_string(name), Util::share_string(value)); - } - void _addProperty(Util::ptr_shared name, long value) { - _addFormattedProperty(name, "%ld", value); + _addProperty(name, Util::share_string(value)); } void _addProperty(char const *name, long value) { - _addProperty(Util::share_string(name), value); + _addFormattedProperty(name, "%ld", value); } private: - Util::ptr_shared _name; + char const *_name; std::vector<PropertyPair, GC::Alloc<PropertyPair, GC::AUTO> > _properties; - void _addFormattedProperty(Util::ptr_shared name, char const *format, ...) + void _addFormattedProperty(char const *name, char const *format, ...) { va_list args; va_start(args, format); |
