From 8757dd0458eba961a7837cc00210e65c639bd82b Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sat, 23 Oct 2021 14:28:27 +0200 Subject: query: use a switch instead of if/else chains --- query.zig | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'query.zig') diff --git a/query.zig b/query.zig index 6d9c4eb..e4113bd 100644 --- a/query.zig +++ b/query.zig @@ -132,14 +132,17 @@ pub const ParsedQuery = struct { } // The last character was ? so this must be an untyped bind marker. - if (state == .BindMarker) { - parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = null; - parsed_query.nb_bind_markers += 1; - } else if (state == .BindMarkerIdentifier) { - parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier = std.fmt.comptimePrint("{s}", .{current_bind_marker_id[0..current_bind_marker_id_pos]}); - parsed_query.nb_bind_markers += 1; - } else if (state == .BindMarkerType) { - @compileError("invalid final state " ++ @tagName(state) ++ ", this means you wrote an incomplete bind marker type"); + switch (state) { + .BindMarker => { + parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = null; + parsed_query.nb_bind_markers += 1; + }, + .BindMarkerIdentifier => { + parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier = std.fmt.comptimePrint("{s}", .{current_bind_marker_id[0..current_bind_marker_id_pos]}); + parsed_query.nb_bind_markers += 1; + }, + .Start => {}, + else => @compileError("invalid final state " ++ @tagName(state) ++ ", this means you wrote an incomplete bind marker type"), } mem.copy(u8, &parsed_query.query, &buf); -- cgit v1.2.3