Просмотр исходного кода

Reduced size by 52 bytes by inlining createNode()

Benoit Blanchon 11 лет назад
Родитель
Сommit
e94089ca56
2 измененных файлов с 9 добавлено и 10 удалено
  1. 9 3
      include/ArduinoJson/Internals/List.hpp
  2. 0 7
      src/Internals/List.cpp

+ 9 - 3
include/ArduinoJson/Internals/List.hpp

@@ -6,9 +6,10 @@
 
 #pragma once
 
-#include "ListIterator.hpp"
-#include "ListConstIterator.hpp"
 #include "../JsonBuffer.hpp"
+#include "ListConstIterator.hpp"
+#include "ListIterator.hpp"
+#include "PlacementNew.hpp"
 
 namespace ArduinoJson {
 namespace Internals {
@@ -48,7 +49,12 @@ class List {
   const_iterator end() const { return const_iterator(NULL); }
 
  protected:
-  node_type *createNode();
+  node_type *createNode() {
+    if (!_buffer) return NULL;
+    void *ptr = _buffer->alloc(sizeof(node_type));
+    return ptr ? new (ptr) node_type() : NULL;
+  }
+
   void addNode(node_type *node);
   void removeNode(node_type *nodeToRemove);
 

+ 0 - 7
src/Internals/List.cpp

@@ -20,13 +20,6 @@ int List<T>::size() const {
   return nodeCount;
 }
 
-template <typename T>
-typename List<T>::node_type *List<T>::createNode() {
-  if (!_buffer) return NULL;
-  void *ptr = _buffer->alloc(sizeof(node_type));
-  return ptr ? new (ptr) node_type() : NULL;
-}
-
 template <typename T>
 void List<T>::addNode(node_type *nodeToAdd) {
   if (_firstNode) {