AttributeMetadata: use vector.reserve() instead of resize() and [i] and thus avoid unwanted AttributeMetadata() constructor call v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Sep 2018 23:22:50 +0200
branchv_0
changeset 25 fc0d05b72214
parent 24 6f7acc3b274c
child 26 019edca46769
AttributeMetadata: use vector.reserve() instead of resize() and [i] and thus avoid unwanted AttributeMetadata() constructor call
include/relpipe/reader/handlers/AttributeMetadata.h
src/StreamRelationalReader.h
--- a/include/relpipe/reader/handlers/AttributeMetadata.h	Sat Sep 15 22:52:15 2018 +0200
+++ b/include/relpipe/reader/handlers/AttributeMetadata.h	Sat Sep 15 23:22:50 2018 +0200
@@ -14,10 +14,6 @@
 public:
 	~AttributeMetadata();
 
-	AttributeMetadata() {
-		std::cout << "FIXME: why call AttributeMetadata() ?" << std::endl;
-	}
-
 	AttributeMetadata(AttributeMetadataPrivate* impl) :
 	impl(impl) {
 	}
--- a/src/StreamRelationalReader.h	Sat Sep 15 22:52:15 2018 +0200
+++ b/src/StreamRelationalReader.h	Sat Sep 15 23:22:50 2018 +0200
@@ -142,24 +142,23 @@
 				// Read column count
 				columnCount = integerReader.readValue(input);
 
-				columnTypes.resize(columnCount);
-				columnNames.resize(columnCount);
-				columns.resize(columnCount);
+				columnTypes.reserve(columnCount);
+				columnNames.reserve(columnCount);
+				columns.reserve(columnCount);
 
 				// Read column names
 				for (int i = 0; i < columnCount; i++) {
-					columnNames[i] = stringReader.readValue(input);
+					columnNames.push_back(stringReader.readValue(input));
 				}
 
 				// Read column types
 				for (int i = 0; i < columnCount; i++) {
 					TypeId typeId = (TypeId) integerReader.readValue(input); // TODO: přetypování OK?
 					string_t typeCode = toTypeCode(typeId); // validate typeId TODO: je potřeba?
-					columnTypes[i] = typeId;
+					columnTypes.push_back(typeId);
 
 					// put together names, type ids and type codes:
-					handlers::AttributeMetadataPrivate* xxx = new handlers::AttributeMetadataPrivate({columnNames[i], columnTypes[i], typeCode});
-					columns[i] = handlers::AttributeMetadata(xxx);
+					columns.push_back(handlers::AttributeMetadata(new handlers::AttributeMetadataPrivate({columnNames[i], columnTypes[i], typeCode})));
 				}
 
 				for (StringHandler* handler : stringHandlers) handler->startRelation(tableName, columns);