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

Unified Diff: runtime/vm/object.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: code review 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
« no previous file with comments | « runtime/vm/json_stream.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index ceecf06cf872c430d42e6b0508dd92e3b9d3a821..2b438ec73f37aa541487a1e452b614f9f8081d95 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -20086,10 +20086,21 @@ void Array::PrintJSONImpl(JSONStream* stream, bool ref) const {
if (ref) {
return;
}
+ intptr_t offset;
+ intptr_t count;
+ stream->ComputeOffsetAndCount(Length(), &offset, &count);
+ if (offset > 0) {
+ jsobj.AddProperty("offset", offset);
+ }
+ if (count < Length()) {
+ jsobj.AddProperty("count", count);
+ }
+ intptr_t limit = offset + count;
+ ASSERT(limit <= Length());
{
JSONArray jsarr(&jsobj, "elements");
Object& element = Object::Handle();
- for (intptr_t index = 0; index < Length(); index++) {
+ for (intptr_t index = offset; index < limit; index++) {
element = At(index);
jsarr.AddValue(element);
}
@@ -20324,10 +20335,21 @@ void GrowableObjectArray::PrintJSONImpl(JSONStream* stream,
if (ref) {
return;
}
+ intptr_t offset;
+ intptr_t count;
+ stream->ComputeOffsetAndCount(Length(), &offset, &count);
+ if (offset > 0) {
+ jsobj.AddProperty("offset", offset);
+ }
+ if (count < Length()) {
+ jsobj.AddProperty("count", count);
+ }
+ intptr_t limit = offset + count;
+ ASSERT(limit <= Length());
{
JSONArray jsarr(&jsobj, "elements");
Object& element = Object::Handle();
- for (intptr_t index = 0; index < Length(); index++) {
+ for (intptr_t index = offset; index < limit; index++) {
element = At(index);
jsarr.AddValue(element);
}
@@ -20430,16 +20452,31 @@ void LinkedHashMap::PrintJSONImpl(JSONStream* stream, bool ref) const {
if (ref) {
return;
}
+ intptr_t offset;
+ intptr_t count;
+ stream->ComputeOffsetAndCount(Length(), &offset, &count);
+ if (offset > 0) {
+ jsobj.AddProperty("offset", offset);
+ }
+ if (count < Length()) {
+ jsobj.AddProperty("count", count);
+ }
+ intptr_t limit = offset + count;
+ ASSERT(limit <= Length());
{
JSONArray jsarr(&jsobj, "associations");
Object& object = Object::Handle();
LinkedHashMap::Iterator iterator(*this);
- while (iterator.MoveNext()) {
- JSONObject jsassoc(&jsarr);
- object = iterator.CurrentKey();
- jsassoc.AddProperty("key", object);
- object = iterator.CurrentValue();
- jsassoc.AddProperty("value", object);
+ int i = 0;
+ while (iterator.MoveNext() && i < limit) {
+ if (i >= offset) {
+ JSONObject jsassoc(&jsarr);
+ object = iterator.CurrentKey();
+ jsassoc.AddProperty("key", object);
+ object = iterator.CurrentValue();
+ jsassoc.AddProperty("value", object);
+ }
+ i++;
}
}
}
@@ -20831,12 +20868,23 @@ void TypedData::PrintJSONImpl(JSONStream* stream, bool ref) const {
if (ref) {
return;
}
-
- {
+ intptr_t offset;
+ intptr_t count;
+ stream->ComputeOffsetAndCount(Length(), &offset, &count);
+ if (offset > 0) {
+ jsobj.AddProperty("offset", offset);
+ }
+ if (count < Length()) {
+ jsobj.AddProperty("count", count);
+ }
+ if (count == 0) {
+ jsobj.AddProperty("bytes", "");
+ } else {
NoSafepointScope no_safepoint;
jsobj.AddPropertyBase64("bytes",
- reinterpret_cast<const uint8_t*>(DataAddr(0)),
- LengthInBytes());
+ reinterpret_cast<const uint8_t*>(
+ DataAddr(offset * ElementSizeInBytes())),
+ count * ElementSizeInBytes());
}
}
@@ -20882,12 +20930,23 @@ void ExternalTypedData::PrintJSONImpl(JSONStream* stream,
if (ref) {
return;
}
-
- {
+ intptr_t offset;
+ intptr_t count;
+ stream->ComputeOffsetAndCount(Length(), &offset, &count);
+ if (offset > 0) {
+ jsobj.AddProperty("offset", offset);
+ }
+ if (count < Length()) {
+ jsobj.AddProperty("count", count);
+ }
+ if (count == 0) {
+ jsobj.AddProperty("bytes", "");
+ } else {
NoSafepointScope no_safepoint;
jsobj.AddPropertyBase64("bytes",
- reinterpret_cast<const uint8_t*>(DataAddr(0)),
- LengthInBytes());
+ reinterpret_cast<const uint8_t*>(
+ DataAddr(offset * ElementSizeInBytes())),
+ count * ElementSizeInBytes());
}
}
« no previous file with comments | « runtime/vm/json_stream.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698