serialization: move StrictHashMap related services
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 27 Jul 2017 03:30:10 +0000 (23:30 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 31 Aug 2017 20:00:09 +0000 (16:00 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/serialization/engine_tools.nit
lib/serialization/serialization.nit
tests/sav/nitserial_args1.res

index f085749..d43da6d 100644 (file)
@@ -36,6 +36,7 @@ class StrictHashMap[K, V]
                var c = _array[i]
                while c != null do
                        var ck = c._key
+                       assert ck != null
                        if ck.is_same_serialized(k) then
                                break
                        end
@@ -45,6 +46,19 @@ class StrictHashMap[K, V]
        end
 end
 
+redef interface Object
+       # Is `self` the same as `other` in a serialization context?
+       #
+       # Used to determine if an object has already been serialized.
+       fun is_same_serialized(other: nullable Object): Bool do return is_same_instance(other)
+
+       # Hash value use for serialization
+       #
+       # Used in combination with `is_same_serialized`. If two objects are the same
+       # in a serialization context, they must have the same `serialization_hash`.
+       fun serialization_hash: Int do return object_id
+end
+
 redef class Text
 
        # Strip the `nullable` prefix from the type name `self`
index 3147cad..3feb4ee 100644 (file)
@@ -247,19 +247,6 @@ interface Serializable
        init from_deserializer(deserializer: Deserializer) is nosuper do end
 end
 
-redef interface Object
-       # Is `self` the same as `other` in a serialization context?
-       #
-       # Used to determine if an object has already been serialized.
-       fun is_same_serialized(other: nullable Object): Bool do return is_same_instance(other)
-
-       # Hash value use for serialization
-       #
-       # Used in combination with `is_same_serialized`. If two objects are the same
-       # in a serialization context, they must have the same `serialization_hash`.
-       fun serialization_hash: Int do return object_id
-end
-
 # Instances of this class are not delayed and instead serialized immediately
 # This applies mainly to `universal` types
 interface DirectSerializable
index 8f3e651..f8172b0 100644 (file)
@@ -13,11 +13,11 @@ redef class Deserializer
        redef fun deserialize_class(name)
        do
                # Module: test_serialization
-               if name == "Array[Text]" then return new Array[Text].from_deserializer(self)
                if name == "Array[Map[String, nullable Object]]" then return new Array[Map[String, nullable Object]].from_deserializer(self)
                if name == "Array[String]" then return new Array[String].from_deserializer(self)
-               if name == "StrictHashMap[Int, Object]" then return new StrictHashMap[Int, Object].from_deserializer(self)
+               if name == "Array[Text]" then return new Array[Text].from_deserializer(self)
                if name == "Array[Error]" then return new Array[Error].from_deserializer(self)
+               if name == "StrictHashMap[Int, Object]" then return new StrictHashMap[Int, Object].from_deserializer(self)
                if name == "POSet[String]" then return new POSet[String].from_deserializer(self)
                if name == "Array[Int]" then return new Array[Int].from_deserializer(self)
                if name == "Array[nullable Object]" then return new Array[nullable Object].from_deserializer(self)