Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: Source/bindings/core/v8/V8Binding.h

Issue 947123002: [bindings] Split toUInt32 into faster inline and non-inline slower path. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/bindings/core/v8/V8Binding.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/V8Binding.h
diff --git a/Source/bindings/core/v8/V8Binding.h b/Source/bindings/core/v8/V8Binding.h
index abbd3fdcb5e710b26fa3e970e9fbc827d746710e..b705e352af6da2c6f64ec52952bacede1be60b82 100644
--- a/Source/bindings/core/v8/V8Binding.h
+++ b/Source/bindings/core/v8/V8Binding.h
@@ -432,7 +432,29 @@ int32_t toInt32(v8::Handle<v8::Value>);
// Convert a value to a 32-bit unsigned integer. The conversion fails if the
// value cannot be converted to a number or the range violated per WebIDL:
// http://www.w3.org/TR/WebIDL/#es-unsigned-long
-uint32_t toUInt32(v8::Handle<v8::Value>, IntegerConversionConfiguration, ExceptionState&);
+uint32_t toUInt32Slow(v8::Handle<v8::Value>, IntegerConversionConfiguration, ExceptionState&);
+inline uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
+{
+ // Fast case. The value is already a 32-bit unsigned integer.
+ if (value->IsUint32())
+ return value->Uint32Value();
+
+ // Fast case. The value is a 32-bit signed integer - possibly positive?
+ if (value->IsInt32()) {
+ int32_t result = value->Int32Value();
+ if (result >= 0)
+ return result;
+ if (configuration == EnforceRange) {
Jens Widell 2015/02/23 11:41:56 I think in principle that we're inlining too much
+ exceptionState.throwTypeError("Value is outside the 'unsigned long' value range.");
+ return 0;
+ }
+ if (configuration == Clamp)
+ return clampTo<uint32_t>(result);
+ return result;
+ }
+ return toUInt32Slow(value, configuration, exceptionState);
+}
+
inline uint32_t toUInt32(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
{
return toUInt32(value, NormalConversion, exceptionState);
« no previous file with comments | « no previous file | Source/bindings/core/v8/V8Binding.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698