Chromium Code Reviews

Unified Diff: src/objects-inl.h

Issue 2577143002: [runtime] Add PositiveNumberToUint32 helper to avoid double to uint roundtrip (Closed)
Patch Set: avoid overflows Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « src/objects.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index b1165b3ae7ea74daef4df6ec236d76fdc3b2eaf7..b6e667700c488aacce53233cf5f19959ed9d54f1 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -3853,6 +3853,12 @@ inline Vector<const uc16> String::GetCharVector() {
return flat.ToUC16Vector();
}
+uint32_t String::ToValidIndex(Object* number) {
+ uint32_t index = PositiveNumberToUint32(number);
+ uint32_t length_value = static_cast<uint32_t>(length());
+ if (index > length_value) return length_value;
+ return index;
+}
uint16_t SeqOneByteString::SeqOneByteStringGet(int index) {
DCHECK(index >= 0 && index < length());
« no previous file with comments | « src/objects.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine