Skip to content

Commit

Permalink
Lazy cache std types
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Aug 20, 2024
1 parent f8a0339 commit 8fd5438
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/json2object/utils/schema/DataBuilder.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,43 @@ typedef Definitions = Map<String, JsonType>;

class DataBuilder {

static var BOOL = Context.getType("Bool");
static var FLOAT = Context.getType("Float");
static var STRING = Context.getType("String");
@:persistent
static var cachedBool:Type = null;
@:persistent
static var cachedFloat:Type = null;
@:persistent
static var cachedString:Type = null;

static var BOOL(get, never):Type;
static var FLOAT(get, never):Type;
static var STRING(get, never):Type;

static function get_BOOL() {
return switch cachedBool {
case null:
cachedBool = Context.getType("Bool");
case cached:
cached;
}
}

static function get_FLOAT() {
return switch cachedFloat {
case null:
cachedFloat = Context.getType("Float");
case cached:
cached;
}
}

static function get_STRING() {
return switch cachedString {
case null:
cachedString = Context.getType("String");
case cached:
cached;
}
}

@:persistent
private static var writers = new Map<String, Bool>();
Expand Down

0 comments on commit 8fd5438

Please sign in to comment.