diff --git a/app/Benchmarks/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents b/app/Benchmarks/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents index 303e371a6..0815aa355 100644 --- a/app/Benchmarks/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents +++ b/app/Benchmarks/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents @@ -10,12 +10,6 @@ - - - - - - diff --git a/app/Benchmarks/ViewController.swift b/app/Benchmarks/ViewController.swift index 1e76d1cdc..7572c8d2c 100644 --- a/app/Benchmarks/ViewController.swift +++ b/app/Benchmarks/ViewController.swift @@ -72,6 +72,10 @@ final class BenchmarksViewController: UIViewController { for i in 0.. Bool { - guard let sqlite = ((toolbox as? SQLitePersistenceToolbox).map { $0.connection }) else { return false } - switch field { - default: - break - } return true } } diff --git a/src/parser/dflatc.swift b/src/parser/dflatc.swift index 0438b6542..4f9de1cef 100644 --- a/src/parser/dflatc.swift +++ b/src/parser/dflatc.swift @@ -805,23 +805,25 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { } code += " }\n" code += " public static func insertIndex(_ toolbox: PersistenceToolbox, field: String, rowid: Int64, table: ByteBuffer) -> Bool {\n" - code += " guard let sqlite = ((toolbox as? SQLitePersistenceToolbox).map { $0.connection }) else { return false }\n" - code += " switch field {\n" - for indexedField in indexedFields { - code += " case \"\(indexedField.keyName)\":\n" - code += " guard let insert = sqlite.prepareStatement(\"INSERT INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return false }\n" - code += " rowid.bindSQLite(insert, parameterId: 1)\n" - code += " let retval = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .table(table))\n" - code += " if retval.unknown {\n" - code += " sqlite3_bind_null(insert, 2)\n" - code += " } else {\n" - code += " retval.result.bindSQLite(insert, parameterId: 2)\n" - code += " }\n" - code += " guard SQLITE_DONE == sqlite3_step(insert) else { return false }\n" + if indexedFields.count > 0 { + code += " guard let sqlite = ((toolbox as? SQLitePersistenceToolbox).map { $0.connection }) else { return false }\n" + code += " switch field {\n" + for indexedField in indexedFields { + code += " case \"\(indexedField.keyName)\":\n" + code += " guard let insert = sqlite.prepareStatement(\"INSERT INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return false }\n" + code += " rowid.bindSQLite(insert, parameterId: 1)\n" + code += " let retval = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .table(table))\n" + code += " if retval.unknown {\n" + code += " sqlite3_bind_null(insert, 2)\n" + code += " } else {\n" + code += " retval.result.bindSQLite(insert, parameterId: 2)\n" + code += " }\n" + code += " guard SQLITE_DONE == sqlite3_step(insert) else { return false }\n" + } + code += " default:\n" + code += " break\n" + code += " }\n" } - code += " default:\n" - code += " break\n" - code += " }\n" code += " return true\n" code += " }\n" code += "}\n" diff --git a/src/tests/monster_generated.json b/src/tests/monster_generated.json deleted file mode 100644 index e1594466a..000000000 --- a/src/tests/monster_generated.json +++ /dev/null @@ -1 +0,0 @@ -{"enums": [{"is_union": false, "name": "Color", "namespace": ["MyGame", "Sample"], "underlying_type": "byte", "fields": [{"name": "Red", "type": "", "value": 0}, {"name": "Green", "type": "", "value": 1}, {"name": "Blue", "type": "", "value": 2}]}, {"is_union": true, "name": "Equipment", "namespace": ["MyGame", "Sample"], "fields": [{"name": "NONE", "type": "", "value": 0}, {"name": "Weapon", "type": "struct", "struct": "Weapon", "value": 1}, {"name": "Orb", "type": "struct", "struct": "Orb", "value": 2}]}], "structs": [{"fixed": true, "name": "Vec3", "namespace": ["MyGame", "Sample"], "fields": [{"name": "x", "deprecated": false, "type": {"type": "float"}, "default": "0.0", "attributes": []}, {"name": "y", "deprecated": false, "type": {"type": "float"}, "default": "0.0", "attributes": []}, {"name": "z", "deprecated": false, "type": {"type": "float"}, "default": "0.0", "attributes": []}]}, {"fixed": false, "name": "Monster", "namespace": ["MyGame", "Sample"], "fields": [{"name": "pos", "deprecated": false, "type": {"type": "struct", "struct": "Vec3"}, "attributes": []}, {"name": "mana", "deprecated": false, "type": {"type": "short"}, "default": "150", "attributes": ["indexed"]}, {"name": "hp", "deprecated": false, "type": {"type": "short"}, "default": "100", "attributes": []}, {"name": "name", "deprecated": false, "type": {"type": "string"}, "attributes": ["primary"]}, {"name": "color", "deprecated": false, "type": {"type": "enum", "enum": "Color"}, "default": "2", "attributes": ["primary"]}, {"name": "friendly", "deprecated": true, "type": {"type": "bool"}, "attributes": ["deprecated"]}, {"name": "inventory", "deprecated": false, "type": {"type": "vector", "element": {"type": "ubyte"}}, "attributes": []}, {"name": "bag_type", "deprecated": false, "type": {"type": "vector", "element": {"type": "utype", "utype": "Equipment"}}, "attributes": []}, {"name": "bag", "deprecated": false, "type": {"type": "vector", "element": {"type": "union", "union": "Equipment"}}, "attributes": []}, {"name": "weapons", "deprecated": false, "type": {"type": "vector", "element": {"type": "struct", "struct": "Weapon"}}, "attributes": []}, {"name": "equipped_type", "deprecated": false, "type": {"type": "utype", "utype": "Equipment"}, "attributes": []}, {"name": "equipped", "deprecated": false, "type": {"type": "union", "union": "Equipment"}, "attributes": ["indexed"]}, {"name": "colors", "deprecated": false, "type": {"type": "vector", "element": {"type": "enum", "enum": "Color"}}, "attributes": []}, {"name": "path", "deprecated": false, "type": {"type": "vector", "element": {"type": "struct", "struct": "Vec3"}}, "attributes": []}]}, {"fixed": false, "name": "Weapon", "namespace": ["MyGame", "Sample"], "fields": [{"name": "name", "deprecated": false, "type": {"type": "string"}, "attributes": []}, {"name": "damage", "deprecated": false, "type": {"type": "short"}, "attributes": []}]}, {"fixed": false, "name": "Orb", "namespace": ["MyGame", "Sample"], "fields": [{"name": "name", "deprecated": false, "type": {"type": "string"}, "attributes": ["unique"]}, {"name": "color", "deprecated": false, "type": {"type": "enum", "enum": "Color"}, "attributes": []}]}], "root": "Monster"} \ No newline at end of file diff --git a/src/tests/monster_v2_generated.json b/src/tests/monster_v2_generated.json deleted file mode 100644 index ec2f6e2c8..000000000 --- a/src/tests/monster_v2_generated.json +++ /dev/null @@ -1 +0,0 @@ -{"enums": [{"is_union": false, "name": "Color", "namespace": ["MyGame", "SampleV2"], "underlying_type": "byte", "fields": [{"name": "Red", "type": "", "value": 0}, {"name": "Green", "type": "", "value": 1}, {"name": "Blue", "type": "", "value": 2}]}, {"is_union": true, "name": "Equipment", "namespace": ["MyGame", "SampleV2"], "fields": [{"name": "NONE", "type": "", "value": 0}, {"name": "Weapon", "type": "struct", "struct": "Weapon", "value": 1}, {"name": "Orb", "type": "struct", "struct": "Orb", "value": 2}]}], "structs": [{"fixed": true, "name": "Vec3", "namespace": ["MyGame", "SampleV2"], "fields": [{"name": "x", "deprecated": false, "type": {"type": "float"}, "default": "0.0", "attributes": []}, {"name": "y", "deprecated": false, "type": {"type": "float"}, "default": "0.0", "attributes": []}, {"name": "z", "deprecated": false, "type": {"type": "float"}, "default": "0.0", "attributes": []}]}, {"fixed": false, "name": "Monster", "namespace": ["MyGame", "SampleV2"], "fields": [{"name": "pos", "deprecated": false, "type": {"type": "struct", "struct": "Vec3"}, "attributes": []}, {"name": "mana", "deprecated": false, "type": {"type": "short"}, "default": "150", "attributes": ["indexed"]}, {"name": "hp", "deprecated": false, "type": {"type": "short"}, "default": "100", "attributes": ["indexed"]}, {"name": "name", "deprecated": false, "type": {"type": "string"}, "attributes": ["primary"]}, {"name": "color", "deprecated": false, "type": {"type": "enum", "enum": "Color"}, "default": "2", "attributes": ["primary"]}, {"name": "friendly", "deprecated": true, "type": {"type": "bool"}, "attributes": ["deprecated"]}, {"name": "inventory", "deprecated": false, "type": {"type": "vector", "element": {"type": "ubyte"}}, "attributes": []}, {"name": "bag_type", "deprecated": true, "type": {"type": "vector", "element": {"type": "utype", "utype": "Equipment"}}, "attributes": []}, {"name": "bag", "deprecated": true, "type": {"type": "vector", "element": {"type": "union", "union": "Equipment"}}, "attributes": ["deprecated"]}, {"name": "weapons", "deprecated": false, "type": {"type": "vector", "element": {"type": "struct", "struct": "Weapon"}}, "attributes": []}, {"name": "equipped_type", "deprecated": false, "type": {"type": "utype", "utype": "Equipment"}, "attributes": []}, {"name": "equipped", "deprecated": false, "type": {"type": "union", "union": "Equipment"}, "attributes": ["indexed"]}, {"name": "colors", "deprecated": false, "type": {"type": "vector", "element": {"type": "enum", "enum": "Color"}}, "attributes": []}, {"name": "path", "deprecated": false, "type": {"type": "vector", "element": {"type": "struct", "struct": "Vec3"}}, "attributes": []}, {"name": "wear_type", "deprecated": false, "type": {"type": "utype", "utype": "Equipment"}, "attributes": []}, {"name": "wear", "deprecated": false, "type": {"type": "union", "union": "Equipment"}, "attributes": []}]}, {"fixed": false, "name": "Weapon", "namespace": ["MyGame", "SampleV2"], "fields": [{"name": "name", "deprecated": false, "type": {"type": "string"}, "attributes": []}, {"name": "damage", "deprecated": false, "type": {"type": "short"}, "attributes": []}]}, {"fixed": false, "name": "Orb", "namespace": ["MyGame", "SampleV2"], "fields": [{"name": "name", "deprecated": false, "type": {"type": "string"}, "attributes": ["unique"]}, {"name": "color", "deprecated": false, "type": {"type": "enum", "enum": "Color"}, "attributes": []}]}], "root": "Monster"} \ No newline at end of file