Removed Node.getToVar as it turned out to be a premature

optimization.
This commit is contained in:
Ferdinand Majerech 2011-10-29 22:53:46 +02:00
parent c385a3ae4d
commit b3a51800f7
3 changed files with 15 additions and 46 deletions

Binary file not shown.

View file

@ -336,20 +336,6 @@
<b>Throws:</b><div class="pbr">NodeException if unable to convert to specified type, or if <b>Throws:</b><div class="pbr">NodeException if unable to convert to specified type, or if
the value is out of range of requested type.</div> the value is out of range of requested type.</div>
</dd>
<dt class="d_decl">void <a name="getToVar"></a><span class="ddoc_psymbol">getToVar</span>(T)(out T <b>target</b>);
</dt>
<dd><p>Write the value of the node to target.
</p>
<p>If the target type does not match node type,
conversion is attempted.
</p>
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>target</td>
<td valign=top>Variable to write to.</td></tr>
</table></div>
<b>Throws:</b><div class="pbr">NodeException if unable to convert to specified type.</div>
</dd> </dd>
<dt class="d_decl">@property size_t <a name="length"></a><span class="ddoc_psymbol">length</span>(); <dt class="d_decl">@property size_t <a name="length"></a><span class="ddoc_psymbol">length</span>();
</dt> </dt>

View file

@ -512,28 +512,10 @@ struct Node
* the value is out of range of requested type. * the value is out of range of requested type.
*/ */
@property T get(T)() if(!is(T == const)) @property T get(T)() if(!is(T == const))
{
T result;
getToVar!T(result);
return result;
}
/**
* Write the value of the node to target.
*
* If the target type does not match node type,
* conversion is attempted.
*
* Params: target = Variable to write to.
*
* Throws: NodeException if unable to convert to specified type.
*/
void getToVar(T)(out T target) if(!is(T == const))
{ {
if(isType!T) if(isType!T)
{ {
target = value_.get!T; return value_.get!T;
return;
} }
static if(!Value.allowed!T) static if(!Value.allowed!T)
@ -544,8 +526,7 @@ struct Node
auto object = as!YAMLObject; auto object = as!YAMLObject;
if(object.type is typeid(T)) if(object.type is typeid(T))
{ {
target = (cast(YAMLContainer!T)object).value_; return (cast(YAMLContainer!T)object).value_;
return;
} }
} }
} }
@ -554,8 +535,7 @@ struct Node
//we're getting the default value. //we're getting the default value.
if(isMapping) if(isMapping)
{ {
target = this["="].as!T; return this["="].as!T;
return;
} }
void throwUnexpectedType() void throwUnexpectedType()
@ -570,8 +550,7 @@ struct Node
//Try to convert to string. //Try to convert to string.
try try
{ {
target = value_.coerce!T(); return value_.coerce!T();
return;
} }
catch(VariantException e) catch(VariantException e)
{ {
@ -583,37 +562,41 @@ struct Node
///Can convert int to float. ///Can convert int to float.
if(isInt()) if(isInt())
{ {
target = to!T(value_.get!long); return to!T(value_.get!long);
return;
} }
else if(isFloat()) else if(isFloat())
{ {
target = to!T(value_.get!real); return to!T(value_.get!real);
return; }
else
{
throwUnexpectedType();
assert(false);
} }
} }
else static if(isIntegral!T) else static if(isIntegral!T)
{ {
if(isInt()) if(isInt())
{ {
long temp = value_.get!long; const temp = value_.get!long;
if(temp < T.min || temp > T.max) if(temp < T.min || temp > T.max)
{ {
throw new Error("Integer value out of range of type " ~ throw new Error("Integer value out of range of type " ~
typeid(T).toString ~ "Value: " ~ to!string(temp), typeid(T).toString ~ "Value: " ~ to!string(temp),
startMark_); startMark_);
} }
target = to!T(temp); return to!T(temp);
return;
} }
else else
{ {
throwUnexpectedType(); throwUnexpectedType();
assert(false);
} }
} }
else else
{ {
throwUnexpectedType(); throwUnexpectedType();
assert(false);
} }
} }