Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/FileSystemJsObject.cpp

Issue 29481704: Noissue - Use buffer for FileSystem IO (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created July 6, 2017, 9:19 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 : IoThread(jsEngine, callback), path(path) 54 : IoThread(jsEngine, callback), path(path)
55 { 55 {
56 } 56 }
57 57
58 void Run() 58 void Run()
59 { 59 {
60 std::string content; 60 std::string content;
61 std::string error; 61 std::string error;
62 try 62 try
63 { 63 {
64 std::shared_ptr<std::istream> stream = fileSystem->Read(path); 64 auto buffer = fileSystem->Read(path);
65 content = Utils::Slurp(*stream); 65 content = std::string(buffer.cbegin(), buffer.cend());
66 } 66 }
67 catch (std::exception& e) 67 catch (std::exception& e)
68 { 68 {
69 error = e.what(); 69 error = e.what();
70 } 70 }
71 catch (...) 71 catch (...)
72 { 72 {
73 error = "Unknown error while reading from " + path; 73 error = "Unknown error while reading from " + path;
74 } 74 }
75 75
(...skipping 17 matching lines...) Expand all
93 const std::string& path, const std::string& content) 93 const std::string& path, const std::string& content)
94 : IoThread(jsEngine, callback), path(path), content(content) 94 : IoThread(jsEngine, callback), path(path), content(content)
95 { 95 {
96 } 96 }
97 97
98 void Run() 98 void Run()
99 { 99 {
100 std::string error; 100 std::string error;
101 try 101 try
102 { 102 {
103 std::stringstream stream; 103 FileSystem::IOBuffer buffer(content.cbegin(), content.cend());
104 stream << content; 104 fileSystem->Write(path, buffer);
105 fileSystem->Write(path, stream);
106 } 105 }
107 catch (std::exception& e) 106 catch (std::exception& e)
108 { 107 {
109 error = e.what(); 108 error = e.what();
110 } 109 }
111 catch (...) 110 catch (...)
112 { 111 {
113 error = "Unknown error while writing to " + path; 112 error = "Unknown error while writing to " + path;
114 } 113 }
115 114
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj) 334 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj)
336 { 335 {
337 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback)); 336 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback));
338 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback)); 337 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback));
339 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback)); 338 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback));
340 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback)); 339 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback));
341 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback)); 340 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback));
342 obj.SetProperty("resolve", jsEngine.NewCallback(::ResolveCallback)); 341 obj.SetProperty("resolve", jsEngine.NewCallback(::ResolveCallback));
343 return obj; 342 return obj;
344 } 343 }
OLDNEW
« src/DefaultFileSystem.cpp ('K') | « src/DefaultFileSystem.cpp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld