faml 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c75f4eb1e20a0f8b34c9727c3bc6f71dfa968ffe
4
- data.tar.gz: a488b7a8c9786cbd0da1c23a2631ab00b3001324
3
+ metadata.gz: c14024dd27014d4d1b41a1313b1e85f2ba2d4be2
4
+ data.tar.gz: 1125ce25dca9c6daafe7fc42d04be96057ad9ba6
5
5
  SHA512:
6
- metadata.gz: 5ffad9305eba0e7af43647e43d79b5ba67074a3657414d0a19ac361b1954b155c022e01d4c26a876eec740a0498c9db0184cc71db90c6d0679fbcc7555793208
7
- data.tar.gz: f8a2342f8a888fe2293187ea532b03e0c2bef59fbe58c88acec5f80ae6dcef2c2e996db23b0018c69f3d4114cee8b1a547ff1d796bb62e49a817a8ce2fb11de7
6
+ metadata.gz: 0b39519a1514a4eb09800291310e7be514a70f8d51ec1eff80f048baafa7fe8237b93ae2cba8ff4ea400a1a0559a89ad4574bd3e12e031684ac34579095982e6
7
+ data.tar.gz: 2f0f94f8ee613989a4476d0d7165e1712259be33cb679834f1f2eb9a625c384bd26dc49fdb1ec2c713519531d4107a2b8d5dd70d8227264c20463c72c9a108d5
@@ -1,3 +1,8 @@
1
+ ## 0.7.2 (2015-12-13)
2
+ - Improve AttributeBuilder performance
3
+ - Replace std::ostringstream with std::string
4
+ - Fix compile error in some platforms
5
+
1
6
  ## 0.7.1 (2015-12-04)
2
7
  - Fix compiler options for old compilers
3
8
 
@@ -18,7 +23,7 @@
18
23
  - https://github.com/eagletmt/faml/pull/41
19
24
 
20
25
  ## 0.6.3 (2015-11-22)
21
- - Remove duplicated class in Ruby attribute case
26
+ - Remove duplicated class in runtime attribute case
22
27
  - `%span.foo{h}` where `h = { class: 'foo bar' }` now renders `<span class='bar foo'></span>` .
23
28
  - `%span.foo{class: 'foo bar'}` renders `<span class='bar foo'></span>` since v0.2.12 .
24
29
 
data/README.md CHANGED
@@ -90,7 +90,7 @@ You have to set `Faml::Engine.options[:extend_helpers] = true` to use `preserve`
90
90
  ### Others
91
91
  If you find other incompatibility, please report it to me :-p.
92
92
 
93
- ## Why faml is faster?
93
+ ## Why is faml faster?
94
94
  ### Temple backend
95
95
  I use [temple](https://github.com/judofyr/temple) to achieve faster template rendering.
96
96
  It's used by [slim](https://github.com/slim-template/slim) template language & engine which is known as fast.
@@ -120,18 +120,18 @@ The runtime hash merging is implemented by C extension in faml.
120
120
  Internally, attributes are categolized into three types.
121
121
 
122
122
  1. Static attributes
123
- - Both the key and the value are literal.
123
+ - Both the key and the value are static.
124
124
  - Compiled into string literals.
125
125
  - Fastest.
126
126
  - e.g. `%input{checked: false}`
127
127
  2. Dynamic attributes
128
- - The key is literal but the value isn't.
128
+ - The key is static but the value isn't.
129
129
  - The key is compiled into string literal. The value is interpolated at run-time.
130
130
  - Relatively fast.
131
131
  - e.g. `%input{checked: helper_method(@record)}`
132
- 3. Ruby attributes
133
- - Both the key and the value are non-literal expression.
134
- - The attributes are stringified at run-time.
132
+ 3. Runtime attributes
133
+ - Both the key and the value are non-static expression.
134
+ - The attributes are stringified at runtime.
135
135
  - Slow.
136
136
  - e.g. `%input{helper_method(@record)}`
137
137
 
@@ -3,7 +3,6 @@
3
3
  #include "houdini.h"
4
4
  #include <algorithm>
5
5
  #include <map>
6
- #include <sstream>
7
6
  #include <string>
8
7
  #include <vector>
9
8
 
@@ -194,20 +193,20 @@ static void join_class_attribute(attribute_holder& attributes) {
194
193
 
195
194
  std::sort(ary.begin(), ary.end());
196
195
  ary.erase(std::unique(ary.begin(), ary.end()), ary.end());
197
- std::ostringstream oss;
196
+ std::string buf;
198
197
  for (std::vector<std::string>::const_iterator it = ary.begin();
199
198
  it != ary.end(); ++it) {
200
199
  if (it != ary.begin()) {
201
- oss << ' ';
200
+ buf.push_back(' ');
202
201
  }
203
- oss << *it;
202
+ buf.append(*it);
204
203
  }
205
- attributes.upsert("class", attribute_value(oss.str()));
204
+ attributes.upsert("class", attribute_value(buf));
206
205
  }
207
206
 
208
207
  static void join_id_attribute(attribute_holder& attributes) {
209
208
  const std::vector<attribute_value>& ids = attributes.ids_;
210
- std::ostringstream oss;
209
+ std::string buf;
211
210
  bool first = true;
212
211
 
213
212
  for (std::vector<attribute_value>::const_iterator it = ids.begin();
@@ -217,16 +216,16 @@ static void join_id_attribute(attribute_holder& attributes) {
217
216
  break;
218
217
  case ATTRIBUTE_TYPE_TRUE:
219
218
  if (!first) {
220
- oss << '_';
219
+ buf.push_back('_');
221
220
  }
222
- oss << "true";
221
+ buf.append("true");
223
222
  first = false;
224
223
  break;
225
224
  case ATTRIBUTE_TYPE_VALUE:
226
225
  if (!first) {
227
- oss << '_';
226
+ buf.push_back('_');
228
227
  }
229
- oss << it->str_;
228
+ buf.append(it->str_);
230
229
  first = false;
231
230
  break;
232
231
  }
@@ -235,7 +234,7 @@ static void join_id_attribute(attribute_holder& attributes) {
235
234
  return;
236
235
  }
237
236
 
238
- attributes.upsert("id", attribute_value(oss.str()));
237
+ attributes.upsert("id", attribute_value(buf));
239
238
  }
240
239
 
241
240
  static void delete_falsey_values(attributes_type& m) {
@@ -268,34 +267,35 @@ static attributes_type merge(VALUE object_ref, int argc, VALUE* argv) {
268
267
  return attributes.m_;
269
268
  }
270
269
 
271
- static void put_attribute(std::ostringstream& oss,
270
+ static void put_attribute(std::string& buf,
272
271
  const std::string& attr_quote, const std::string& key,
273
272
  const std::string& value) {
274
- oss << " " << key << "=" << attr_quote;
273
+ buf.append(" ").append(key).append("=").append(attr_quote);
275
274
 
276
275
  gh_buf ob = GH_BUF_INIT;
277
276
  if (houdini_escape_html0(&ob, (const uint8_t*)value.data(), value.size(),
278
277
  0)) {
279
- oss << std::string(ob.ptr, ob.size);
278
+ buf.append(std::string(ob.ptr, ob.size));
280
279
  gh_buf_free(&ob);
281
280
  } else {
282
- oss << value;
281
+ buf.append(value);
283
282
  }
284
- oss << attr_quote;
283
+ buf.append(attr_quote);
285
284
  }
286
285
 
287
- static void build_attribute(std::ostringstream& oss,
286
+ static void build_attribute(std::string& buf,
288
287
  const std::string& attr_quote, int is_html,
289
288
  const std::string& key,
290
289
  const attribute_value& value) {
291
290
  if (value.type_ == ATTRIBUTE_TYPE_TRUE) {
292
291
  if (is_html) {
293
- oss << ' ' << key;
292
+ buf.push_back(' ');
293
+ buf.append(key);
294
294
  } else {
295
- put_attribute(oss, attr_quote, key, key);
295
+ put_attribute(buf, attr_quote, key, key);
296
296
  }
297
297
  } else {
298
- put_attribute(oss, attr_quote, key, value.str_);
298
+ put_attribute(buf, attr_quote, key, value.str_);
299
299
  }
300
300
  }
301
301
 
@@ -310,14 +310,13 @@ static VALUE m_build(int argc, VALUE* argv, RB_UNUSED_VAR(VALUE self)) {
310
310
  object_ref = argv[2];
311
311
  const attributes_type attributes = merge(object_ref, argc - 3, argv + 3);
312
312
 
313
- std::ostringstream oss;
313
+ std::string buf;
314
314
  for (attributes_type::const_iterator it = attributes.begin();
315
315
  it != attributes.end(); ++it) {
316
- build_attribute(oss, attr_quote, is_html, it->first, it->second);
316
+ build_attribute(buf, attr_quote, is_html, it->first, it->second);
317
317
  }
318
318
 
319
- const std::string str = oss.str();
320
- return rb_utf8_str_new(str.data(), str.size());
319
+ return rb_utf8_str_new(buf.data(), buf.size());
321
320
  }
322
321
 
323
322
  static VALUE m_normalize_data(RB_UNUSED_VAR(VALUE self), VALUE data) {
@@ -2,7 +2,7 @@
2
2
  require 'mkmf'
3
3
 
4
4
  $CFLAGS << ' -Wall -W'
5
- $CXXFLAGS << ' -Wall -W -std=c++98'
5
+ $CXXFLAGS << ' -Wall -W'
6
6
  houdini_dir = File.expand_path('../../vendor/houdini', __dir__)
7
7
  $INCFLAGS << " -I#{houdini_dir}"
8
8
 
@@ -1,8 +1,8 @@
1
1
  # Incompatibilities
2
2
  ## Versions
3
3
  - Haml 4.1.0.beta.1
4
- - Faml 0.7.1
5
- - Hamlit 2.0.1
4
+ - Faml 0.7.2
5
+ - Hamlit 2.0.2
6
6
 
7
7
  ## Table of contents
8
8
  - [spec/compiler_newline_spec.md](spec/compiler_newline_spec.md)
@@ -13,7 +13,7 @@ module Faml
13
13
  :dynamic_attribute_count,
14
14
  :dynamic_attribute_with_data_count,
15
15
  :dynamic_attribute_with_newline_count,
16
- :ruby_attribute_count,
16
+ :runtime_attribute_count,
17
17
  :object_reference_count,
18
18
  :multi_attribute_count,
19
19
  :ast_types
@@ -133,7 +133,7 @@ module Faml
133
133
  if call_ast.type == :send && call_ast.children[0].nil? && call_ast.children[1] == :call && !call_ast.children[3].nil?
134
134
  info.multi_attribute_count += 1
135
135
  else
136
- info.ruby_attribute_count += 1
136
+ info.runtime_attribute_count += 1
137
137
  end
138
138
  end
139
139
  end
@@ -142,8 +142,8 @@ module Faml
142
142
  def report_attribute_stats(info)
143
143
  static = info.static_attribute_count
144
144
  dynamic = info.dynamic_attribute_count + info.dynamic_attribute_with_data_count + info.dynamic_attribute_with_newline_count
145
- ruby = info.ruby_attribute_count + info.multi_attribute_count + info.object_reference_count
146
- total = static + dynamic + ruby
145
+ runtime = info.runtime_attribute_count + info.multi_attribute_count + info.object_reference_count
146
+ total = static + dynamic + runtime
147
147
  puts 'Attribute stats'
148
148
  printf(" Empty attributes: %d\n", info.empty_attribute_count)
149
149
  printf(" Attributes with id or class only: %d\n", info.static_id_or_class_attribute_count)
@@ -151,7 +151,7 @@ module Faml
151
151
  printf(" Dynamic attributes: %d (%.2f%%)\n", dynamic, dynamic * 100.0 / total)
152
152
  printf(" with data: %d\n", info.dynamic_attribute_with_data_count)
153
153
  printf(" with newline: %d\n", info.dynamic_attribute_with_newline_count)
154
- printf(" Ruby attributes: %d (%.2f%%)\n", ruby, ruby * 100.0 / total)
154
+ printf(" Runtime attributes: %d (%.2f%%)\n", runtime, runtime * 100.0 / total)
155
155
  printf(" with multiple arguments: %d\n", info.multi_attribute_count)
156
156
  printf(" with object reference: %d\n", info.object_reference_count)
157
157
  end
@@ -1,4 +1,4 @@
1
1
  # frozen-string-literal: true
2
2
  module Faml
3
- VERSION = '0.7.1'
3
+ VERSION = '0.7.2'
4
4
  end
@@ -190,7 +190,7 @@ HAML
190
190
  HAML
191
191
  end
192
192
 
193
- it 'keeps newlines in ruby attributes' do
193
+ it 'keeps newlines in runtime attributes' do
194
194
  expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(2))
195
195
  %span{[1,
196
196
  raise(LineVerifier)]}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils
@@ -521,7 +521,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
521
521
  version: '0'
522
522
  requirements: []
523
523
  rubyforge_project:
524
- rubygems_version: 2.4.5.1
524
+ rubygems_version: 2.5.0
525
525
  signing_key:
526
526
  specification_version: 4
527
527
  summary: Faster implementation of Haml template language.