Commit 89d050c0 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] use OS independent number to string conversion

V8 internally uses conversions.h to convert number to string, we can use these methods too instead of slow std::stringstream with std::locale.

BUG=chromium:661497,v8:5551
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2534013002
Cr-Commit-Position: refs/heads/master@{#41334}
parent bc1a3820
......@@ -4,6 +4,7 @@ include_rules = [
"+src/base/macros.h",
"+src/base/logging.h",
"+src/base/platform/platform.h",
"+src/conversions.h",
"+src/inspector",
"+src/tracing",
"-include/v8-debug.h",
......
......@@ -8,13 +8,11 @@
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <limits>
#include <locale>
#include <sstream>
#include <string>
#include "src/base/platform/platform.h"
#include "src/conversions.h"
namespace v8_inspector {
......@@ -366,10 +364,9 @@ static inline void putUTF8Triple(char*& buffer, UChar ch) {
// static
String16 String16::fromInteger(int number) {
const size_t kBufferSize = 50;
char buffer[kBufferSize];
v8::base::OS::SNPrintF(buffer, kBufferSize, "%d", number);
return String16(buffer);
char arr[50];
v8::internal::Vector<char> buffer(arr, arraysize(arr));
return String16(IntToCString(number, buffer));
}
// static
......@@ -386,19 +383,16 @@ String16 String16::fromInteger(size_t number) {
// static
String16 String16::fromDouble(double number) {
std::ostringstream s;
s.imbue(std::locale("C"));
s << std::fixed << std::setprecision(std::numeric_limits<double>::digits10)
<< number;
return String16(s.str().c_str());
char arr[50];
v8::internal::Vector<char> buffer(arr, arraysize(arr));
return String16(DoubleToCString(number, buffer));
}
// static
String16 String16::fromDouble(double number, int precision) {
std::ostringstream s;
s.imbue(std::locale("C"));
s << std::fixed << std::setprecision(precision) << number;
return String16(s.str().c_str());
std::unique_ptr<char[]> str(
v8::internal::DoubleToPrecisionCString(number, precision));
return String16(str.get());
}
int String16::toInteger(bool* ok) const {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment