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

Unified Diff: runtime/bin/dartutils.cc

Issue 2991393002: [standalone] Automatically decompress gzip'd resources, including sources and script snapshots. (Closed)
Patch Set: Fix case in decompression where the snapshot it smaller than the chunk size. Created 3 years, 4 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/bin/dartutils.h ('k') | runtime/bin/dfe.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/dartutils.cc
diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc
index bde946503f9b00190e6d149e3c59af934ef776d6..ed2f6759465f8b1af04dc210dadeeb9f5662aa00 100644
--- a/runtime/bin/dartutils.cc
+++ b/runtime/bin/dartutils.cc
@@ -48,14 +48,15 @@ const char* const DartUtils::kHttpScheme = "http:";
const char* const DartUtils::kVMServiceLibURL = "dart:vmservice";
struct MagicNumberData {
- static const intptr_t kLength = 4;
+ static const intptr_t kMaxLength = 4;
- const uint8_t bytes[kLength];
- bool should_skip;
+ intptr_t length;
+ const uint8_t bytes[kMaxLength];
};
-MagicNumberData snapshot_magic_number = {{0xf5, 0xf5, 0xdc, 0xdc}, true};
-MagicNumberData kernel_magic_number = {{0x90, 0xab, 0xcd, 0xef}, false};
+MagicNumberData snapshot_magic_number = {4, {0xf5, 0xf5, 0xdc, 0xdc}};
+MagicNumberData kernel_magic_number = {4, {0x90, 0xab, 0xcd, 0xef}};
+MagicNumberData gzip_magic_number = {2, {0x1f, 0x8b, 0, 0}};
static bool IsWindowsHost() {
#if defined(HOST_OS_WINDOWS)
@@ -339,40 +340,45 @@ Dart_Handle DartUtils::ResolveScript(Dart_Handle url) {
kNumArgs, dart_args);
}
-static bool CheckMagicNumber(const uint8_t** buf,
- intptr_t* len,
+static bool CheckMagicNumber(const uint8_t* buffer,
+ intptr_t buffer_length,
const MagicNumberData& magic_number) {
- if ((*len >= MagicNumberData::kLength) &&
- (memcmp(*buf, magic_number.bytes, MagicNumberData::kLength) == 0)) {
- if (magic_number.should_skip) {
- *buf += MagicNumberData::kLength;
- *len -= MagicNumberData::kLength;
- }
- return true;
+ if ((buffer_length >= magic_number.length)) {
+ return memcmp(buffer, magic_number.bytes, magic_number.length) == 0;
}
return false;
}
-DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t** buf,
- intptr_t* len) {
- if (CheckMagicNumber(buf, len, snapshot_magic_number)) {
+DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t* buffer,
+ intptr_t buffer_length) {
+ if (CheckMagicNumber(buffer, buffer_length, snapshot_magic_number)) {
return kSnapshotMagicNumber;
}
- if (CheckMagicNumber(buf, len, kernel_magic_number)) {
+ if (CheckMagicNumber(buffer, buffer_length, kernel_magic_number)) {
return kKernelMagicNumber;
}
+ if (CheckMagicNumber(buffer, buffer_length, gzip_magic_number)) {
+ return kGzipMagicNumber;
+ }
+
return kUnknownMagicNumber;
}
-void DartUtils::WriteMagicNumber(File* file) {
+void DartUtils::WriteSnapshotMagicNumber(File* file) {
// Write a magic number and version information into the snapshot file.
- bool bytes_written =
- file->WriteFully(snapshot_magic_number.bytes, MagicNumberData::kLength);
+ bool bytes_written = file->WriteFully(snapshot_magic_number.bytes,
+ snapshot_magic_number.length);
ASSERT(bytes_written);
}
+void DartUtils::SkipSnapshotMagicNumber(const uint8_t** buffer,
+ intptr_t* buffer_length) {
+ *buffer += snapshot_magic_number.length;
+ *buffer_length -= snapshot_magic_number.length;
+}
+
void FUNCTION_NAME(Builtin_GetCurrentDirectory)(Dart_NativeArguments args) {
const char* current = Directory::Current();
if (current != NULL) {
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/dfe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698