summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-09-13 13:45:47 +0200
committerGitHub <noreply@github.com>2018-09-13 13:45:47 +0200
commit023e9c25224a7e13b35f5c52e85c143c5dd9d249 (patch)
tree6d545d1f75f88ec98baee3719263cef8bcf61b74 /document
parente4defa3f3dc0057514e17955515c760aee754670 (diff)
parent1bb96af047350481a2f8027583087a171d4269b2 (diff)
Merge pull request #6918 from vespa-engine/balder/only-use-id-to-compare
Just compare what is necessary for equality.
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/DataType.java4
-rw-r--r--document/src/main/java/com/yahoo/document/ReferenceDataType.java17
-rw-r--r--document/src/vespa/document/datatype/datatype.cpp2
-rw-r--r--document/src/vespa/document/datatype/referencedatatype.cpp6
-rw-r--r--document/src/vespa/document/datatype/referencedatatype.h2
-rw-r--r--document/src/vespa/document/datatype/structdatatype.cpp2
-rw-r--r--document/src/vespa/document/datatype/structdatatype.h8
-rw-r--r--document/src/vespa/document/repo/configbuilder.cpp7
-rw-r--r--document/src/vespa/document/repo/configbuilder.h7
-rw-r--r--document/src/vespa/document/repo/documenttyperepo.cpp2
10 files changed, 39 insertions, 18 deletions
diff --git a/document/src/main/java/com/yahoo/document/DataType.java b/document/src/main/java/com/yahoo/document/DataType.java
index abdbf394591..3f34314f0de 100644
--- a/document/src/main/java/com/yahoo/document/DataType.java
+++ b/document/src/main/java/com/yahoo/document/DataType.java
@@ -246,9 +246,7 @@ public abstract class DataType extends Identifiable implements Serializable, Com
}
public boolean equals(Object other) {
- if (!(other instanceof DataType)) return false;
- DataType type = (DataType)other;
- return (name.equals(type.name) && dataTypeId == type.dataTypeId);
+ return (other instanceof DataType) && (dataTypeId == ((DataType)other).dataTypeId);
}
public String toString() {
diff --git a/document/src/main/java/com/yahoo/document/ReferenceDataType.java b/document/src/main/java/com/yahoo/document/ReferenceDataType.java
index fa6e45ddacd..115917c4118 100644
--- a/document/src/main/java/com/yahoo/document/ReferenceDataType.java
+++ b/document/src/main/java/com/yahoo/document/ReferenceDataType.java
@@ -99,4 +99,21 @@ public class ReferenceDataType extends DataType {
ReferenceFieldValue rhs = (ReferenceFieldValue)value;
return rhs.getDataType().equals(this);
}
+
+ private int compareTargetType(DataType rhs) {
+ return (rhs instanceof ReferenceDataType) ? targetType.compareTo(((ReferenceDataType) rhs).targetType) : 0;
+ }
+
+ @Override
+ public int compareTo(DataType rhs) {
+ int cmp = super.compareTo(rhs);
+ return (cmp != 0) ? cmp : compareTargetType(rhs);
+ }
+
+ @Override
+ public boolean equals(Object rhs) {
+ return super.equals(rhs)
+ && (rhs instanceof ReferenceDataType)
+ && targetType.equals(((ReferenceDataType) rhs).targetType);
+ }
}
diff --git a/document/src/vespa/document/datatype/datatype.cpp b/document/src/vespa/document/datatype/datatype.cpp
index aef155999a4..8d2721a4d9b 100644
--- a/document/src/vespa/document/datatype/datatype.cpp
+++ b/document/src/vespa/document/datatype/datatype.cpp
@@ -159,7 +159,7 @@ DataType::~DataType() = default;
bool
DataType::operator==(const DataType& other) const
{
- return _dataTypeId == other._dataTypeId && _name == other._name;
+ return _dataTypeId == other._dataTypeId;
}
bool
diff --git a/document/src/vespa/document/datatype/referencedatatype.cpp b/document/src/vespa/document/datatype/referencedatatype.cpp
index 6792d95909c..7b7c83c7fa6 100644
--- a/document/src/vespa/document/datatype/referencedatatype.cpp
+++ b/document/src/vespa/document/datatype/referencedatatype.cpp
@@ -41,4 +41,10 @@ void ReferenceDataType::onBuildFieldPath(FieldPath &, vespalib::stringref remain
}
+bool ReferenceDataType::operator==(const DataType &rhs) const {
+ return DataType::operator==(rhs)
+ && rhs.inherits(classId)
+ && (_targetDocType == static_cast<const ReferenceDataType &>(rhs)._targetDocType);
+}
+
} // document
diff --git a/document/src/vespa/document/datatype/referencedatatype.h b/document/src/vespa/document/datatype/referencedatatype.h
index d5804d09835..5ca52f3ccb2 100644
--- a/document/src/vespa/document/datatype/referencedatatype.h
+++ b/document/src/vespa/document/datatype/referencedatatype.h
@@ -24,6 +24,8 @@ public:
void print(std::ostream&, bool verbose, const std::string& indent) const override;
ReferenceDataType* clone() const override;
void onBuildFieldPath(FieldPath & path, vespalib::stringref remainingFieldName) const override;
+
+ bool operator==(const DataType &type) const override;
};
} // document
diff --git a/document/src/vespa/document/datatype/structdatatype.cpp b/document/src/vespa/document/datatype/structdatatype.cpp
index 3ccb08c32be..7c308202e3b 100644
--- a/document/src/vespa/document/datatype/structdatatype.cpp
+++ b/document/src/vespa/document/datatype/structdatatype.cpp
@@ -40,7 +40,7 @@ StructDataType::StructDataType(vespalib::stringref name, int32_t dataTypeId)
_compressionConfig()
{ }
-StructDataType::~StructDataType() { }
+StructDataType::~StructDataType() = default;
StructDataType*
StructDataType::clone() const {
diff --git a/document/src/vespa/document/datatype/structdatatype.h b/document/src/vespa/document/datatype/structdatatype.h
index 4491ed68e01..42003d3b466 100644
--- a/document/src/vespa/document/datatype/structdatatype.h
+++ b/document/src/vespa/document/datatype/structdatatype.h
@@ -71,10 +71,10 @@ public:
DECLARE_IDENTIFIABLE(StructDataType);
private:
- typedef vespalib::hash_map<vespalib::string, Field::SP> StringFieldMap;
- typedef vespalib::hash_map<int32_t, Field::SP> IntFieldMap;
- StringFieldMap _nameFieldMap;
- IntFieldMap _idFieldMap;
+ using StringFieldMap = vespalib::hash_map<vespalib::string, Field::SP>;
+ using IntFieldMap = vespalib::hash_map<int32_t, Field::SP>;
+ StringFieldMap _nameFieldMap;
+ IntFieldMap _idFieldMap;
CompressionConfig _compressionConfig;
/** @return "" if not conflicting. Error message otherwise. */
diff --git a/document/src/vespa/document/repo/configbuilder.cpp b/document/src/vespa/document/repo/configbuilder.cpp
index 45433c2a606..42b37104e04 100644
--- a/document/src/vespa/document/repo/configbuilder.cpp
+++ b/document/src/vespa/document/repo/configbuilder.cpp
@@ -2,8 +2,8 @@
#include "configbuilder.h"
-namespace document {
-namespace config_builder {
+namespace document::config_builder {
+
int32_t createFieldId(const vespalib::string &name, int32_t type) {
StructDataType dummy("dummy", type);
Field f(name, dummy, true);
@@ -63,5 +63,4 @@ DocumenttypesConfigBuilderHelper::document(int32_t id, const vespalib::string &n
return DocTypeRep(_config.documenttype.back());
}
-} // namespace config_builder
-} // namespace document
+}
diff --git a/document/src/vespa/document/repo/configbuilder.h b/document/src/vespa/document/repo/configbuilder.h
index 598c72f6358..c389fd3b09e 100644
--- a/document/src/vespa/document/repo/configbuilder.h
+++ b/document/src/vespa/document/repo/configbuilder.h
@@ -9,8 +9,7 @@
#include <vespa/vespalib/stllike/string.h>
#include <cassert>
-namespace document {
-namespace config_builder {
+namespace document::config_builder {
class TypeOrId;
@@ -143,6 +142,6 @@ public:
::document::DocumenttypesConfigBuilder &config() { return _config; }
};
-} // namespace config_builder
-} // namespace document
+
+}
diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp
index 03b7660efbe..a320750e0d5 100644
--- a/document/src/vespa/document/repo/documenttyperepo.cpp
+++ b/document/src/vespa/document/repo/documenttyperepo.cpp
@@ -89,7 +89,7 @@ void Repo::inherit(const Repo &parent) {
bool Repo::addDataType(const DataType &type) {
const DataType *& data_type = _types[type.getId()];
if (data_type) {
- if (*data_type == type) {
+ if ((*data_type == type) && (data_type->getName() == type.getName())) {
return false; // Redefinition of identical type is ok.
}
throw IllegalArgumentException(