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

Unified Diff: include/v8.h

Issue 2185963002: [api] Add v8::Object::SetAlignedPointerInInternalFields (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: adding fast paths Created 4 years, 5 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 | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 4eb7614210fd1fb3120428e65f7c9ed97394f3b9..d3619f5b744030bc1283c8f31c71961299f30c26 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2891,7 +2891,9 @@ class V8_EXPORT Object : public Value {
* a field, GetAlignedPointerFromInternalField must be used, everything else
* leads to undefined behavior.
*/
- void SetAlignedPointerInInternalField(int index, void* value);
+ V8_INLINE void SetAlignedPointerInInternalField(int index, void* value);
+ V8_INLINE void SetAlignedPointerInInternalFields(int argc, int indices[],
+ void* values[]);
// Testers for local properties.
V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
@@ -3031,6 +3033,9 @@ class V8_EXPORT Object : public Value {
static void CheckCast(Value* obj);
Local<Value> SlowGetInternalField(int index);
void* SlowGetAlignedPointerFromInternalField(int index);
+ void SlowSetAlignedPointerInInternalField(int index, void* value);
+ void SlowSetAlignedPointerInInternalFields(int argc, int indices[],
+ void* values[]);
};
@@ -7701,6 +7706,12 @@ class Internals {
return *reinterpret_cast<const T*>(addr);
}
+ V8_INLINE static void WriteField(internal::Object* ptr, int offset,
+ void* value) {
+ uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
+ *reinterpret_cast<void**>(addr) = value;
+ }
+
template <typename T>
V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
typedef internal::Object O;
@@ -8238,6 +8249,44 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
return SlowGetAlignedPointerFromInternalField(index);
}
+void Object::SetAlignedPointerInInternalField(int index, void* value) {
+#ifndef V8_ENABLE_CHECKS
+ typedef internal::Object O;
+ typedef internal::Internals I;
+ O* object = *reinterpret_cast<O**>(this);
+ // Fast path: If the object is a plain JSObject, which is the common case, we
+ // know where to find the internal fields and can set the value directly.
+ auto instance_type = I::GetInstanceType(object);
+ if (V8_LIKELY(instance_type == I::kJSObjectType ||
+ instance_type == I::kJSApiObjectType)) {
+ int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
+ I::WriteField(object, offset, value);
Michael Starzinger 2016/07/29 09:50:53 Isn't this missing a return? Otherwise the slow ca
+ }
+#endif
+ return SlowSetAlignedPointerInInternalField(index, value);
+}
+
+void Object::SetAlignedPointerInInternalFields(int argc, int indices[],
+ void* values[]) {
+#ifndef V8_ENABLE_CHECKS
+ typedef internal::Object O;
+ typedef internal::Internals I;
+ O* object = *reinterpret_cast<O**>(this);
+ // Fast path: If the object is a plain JSObject, which is the common case, we
+ // know where to find the internal fields and can set the value directly.
+ auto instance_type = I::GetInstanceType(object);
+ if (V8_LIKELY(instance_type == I::kJSObjectType ||
+ instance_type == I::kJSApiObjectType)) {
+ for (int i = 0; i < argc; i++) {
+ int index = indices[i];
+ void* value = values[i];
+ int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
+ I::WriteField(object, offset, value);
Michael Starzinger 2016/07/29 09:50:53 Isn't this missing a return? Otherwise the slow ca
+ }
+ }
+#endif
+ return SlowSetAlignedPointerInInternalFields(argc, indices, values);
+}
String* String::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698