diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2012-03-24 11:24:16 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2012-03-24 11:24:16 -0700 |
commit | 86bad61b76a260ffc442acffbe58feee67df45e5 (patch) | |
tree | e375e62ff6d7fea9fb810830e66118e67b4ec2c8 /bindings/lua/upb.c | |
parent | db59a5198f890ecdcac1227b0bb998160acac5c6 (diff) |
Sync from internal Google development.
Many improvements, too many to mention. One significant
perf regression warrants investigation:
omitfp.parsetoproto2_googlemessage1.upb_jit: 343 -> 252 (-26.53)
plain.parsetoproto2_googlemessage1.upb_jit: 334 -> 251 (-24.85)
25% regression for this benchmark is bad, but since I don't think
there's any fundamental design issue that caused it I'm going to
go ahead with the commit anyway. Can investigate and fix later.
Other benchmarks were neutral or showed slight improvement.
Diffstat (limited to 'bindings/lua/upb.c')
-rw-r--r-- | bindings/lua/upb.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/bindings/lua/upb.c b/bindings/lua/upb.c index 56c5be9..4cce4b6 100644 --- a/bindings/lua/upb.c +++ b/bindings/lua/upb.c @@ -37,11 +37,15 @@ static uint32_t lupb_touint32(lua_State *L, int narg, const char *name) { return n; } -static void lupb_pushstring(lua_State *L, const upb_byteregion *r) { - // TODO: could avoid a copy in the case that the string is contiguous. - char *str = upb_byteregion_strdup(r); - lua_pushlstring(L, str, upb_byteregion_len(r)); - free(str); +static void lupb_pushstring(lua_State *L, const upb_strref *ref) { + if (ref->ptr) { + lua_pushlstring(L, ref->ptr, ref->len); + } else { + // Lua requires a continguous string; must copy+allocate. + char *str = upb_strref_dup(ref); + lua_pushlstring(L, str, ref->len); + free(str); + } } static void lupb_pushvalue(lua_State *L, upb_value val, upb_fielddef *f) { @@ -73,7 +77,7 @@ static void lupb_pushvalue(lua_State *L, upb_value val, upb_fielddef *f) { // Returns a scalar value (ie. not a submessage) as a upb_value. static upb_value lupb_getvalue(lua_State *L, int narg, upb_fielddef *f, - upb_byteregion *ref) { + upb_strref *ref) { assert(!upb_issubmsg(f)); upb_value val; if (upb_fielddef_type(f) == UPB_TYPE(BOOL)) { @@ -135,7 +139,7 @@ static upb_value lupb_getvalue(lua_State *L, int narg, upb_fielddef *f, } static void lupb_typecheck(lua_State *L, int narg, upb_fielddef *f) { - upb_byteregion ref; + upb_strref ref; lupb_getvalue(L, narg, f, &ref); } @@ -298,8 +302,8 @@ static void lupb_fielddef_set(lua_State *L, upb_fielddef *f, } else if (streql(field, "default_value")) { if (!upb_fielddef_type(f)) luaL_error(L, "Must set type before setting default_value"); - upb_byteregion region; - upb_fielddef_setdefault(f, lupb_getvalue(L, narg, f, ®ion)); + upb_strref ref; + upb_fielddef_setdefault(f, lupb_getvalue(L, narg, f, &ref)); } else { luaL_error(L, "Cannot set fielddef member '%s'", field); } @@ -778,7 +782,7 @@ static upb_flow_t lupb_msg_string(void *m, upb_value fval, upb_value val, lua_State *L = *(lua_State**)m; int offset = array ? lua_rawlen(L, -1) : f->offset; if (!lua_checkstack(L, 1)) luaL_error(L, "stack full"); - lupb_pushstring(L, upb_value_getbyteregion(val)); + lupb_pushstring(L, upb_value_getstrref(val)); lua_rawseti(L, -2, offset); return UPB_CONTINUE; } |