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

Unified Diff: runtime/vm/json_stream.cc

Issue 1400393002: Use offset and count to request slices of lists, maps, and typed_data. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: pre review tidy Created 5 years, 2 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
Index: runtime/vm/json_stream.cc
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc
index 2f92daa709accae3701713cb888e7425715d1677..88a72b676ded97964937e7ba88b6312f7a8264bf 100644
--- a/runtime/vm/json_stream.cc
+++ b/runtime/vm/json_stream.cc
@@ -30,7 +30,9 @@ JSONStream::JSONStream(intptr_t buf_size)
method_(""),
param_keys_(NULL),
param_values_(NULL),
- num_params_(0) {
+ num_params_(0),
+ offset_(0),
+ count_(-1) {
ObjectIdRing* ring = NULL;
Isolate* isolate = Isolate::Current();
if (isolate != NULL) {
@@ -245,6 +247,22 @@ bool JSONStream::ParamIs(const char* key, const char* value) const {
}
+void JSONStream::ComputeOffsetAndCount(intptr_t length,
+ intptr_t* offset,
+ intptr_t* count) {
+ // This function is written to avoid adding (count + offset) in case
+ // that triggers an integer overflow.
+ *offset = offset_;
+ if (*offset > length) {
+ *offset = length;
+ }
+ intptr_t remaining = length - *offset;
+ *count = count_;
+ if (*count < 0 || *count > remaining) {
+ *count = remaining;
+ }
+}
+
void JSONStream::Clear() {
buffer_.Clear();
open_objects_ = 0;

Powered by Google App Engine
This is Rietveld 408576698