タグ

tipsとjsonに関するsecondlifeのブックマーク (2)

  • Journal InTime - to_jsonのSafari対策

    _ to_jsonのSafari対策 この間のコードだと、Safariで文字化けしてしまった。 やっぱり\u記法を使わないといけないようだ。 class String JSON_ESCAPED = { "\010" => '\b', "\f" => '\f', "\n" => '\n', "\r" => '\r', "\t" => '\t', '"' => '\"', '\\' => '\\\\' } def to_json return '"' + gsub(/[\010\f\n\r\t"\\]/) { |s| JSON_ESCAPED[s] }.gsub(/([\xC0-\xDF][\x80-\xBF]| [\xE0-\xEF][\x80-\xBF]{2}| [\xF0-\xF7][\x80-\xBF]{3})+/ux) { |s| s.unpack("U*").pack("n*").

  • to_json too slow

    I felt my application slow yesterday and profiled it. RJS is very useful, but it seems to be slow. Thanks to Charlies's ruby-prof (it doesn't belongs to me any more and has fascinating call graph support), I found the bottleneck. It was Object#to_json. The original code is here: define_encoder String do |string| returning value = '"' do string.each_char do |char| value << case when char == "\010":

    secondlife
    secondlife 2006/07/11
    String#to_json を 100倍速に。
  • 1