nokolexbor 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48a8709af6c858df3d9fc1e3de0254f1d44ab308722eabe05a376ecd047eb7ec
4
- data.tar.gz: 5bc0dea72106ead6c1382ef37a730f4b5e7d8ddf273380ef31e37d4d22394106
3
+ metadata.gz: f8686e83a70fe40537a072997e55f11ae40839ccf0b66125e18a251d9ba2c265
4
+ data.tar.gz: edfedec732ab50ee7a68a56c92b0d71166fdcf091c29105b0995e64096c5ebac
5
5
  SHA512:
6
- metadata.gz: a025216fbd78c4b399b0938b4750d1eba72b3ed7e78d511222497a94ae904e8ed04a607641ab7d3dc4002d15763b47f4b8a4631575f82be022e6a719e08d0a7d
7
- data.tar.gz: 61a219e89f430b2d726b8a676674fc9c5dfa924c8e75e878ba4637a135b04c25dc3cb3cc8e9a437cc6c8fc8099ede8fb14d506766c40df1bba5261e5fbabeb56
6
+ metadata.gz: be9df7bc7747b0d155764069f6782e27127127c1c2ec74394b1d9ae01c56b3428811ee4aec1bf4e89fbc8bd6be61508d6dd26b93bd9929c2fdd70cb4e1b28a7d
7
+ data.tar.gz: 91d16cbe5143e480bd52f5fdbcfe7aa57ca8127cb8f4ea9f249280f027264297426c00f5c5525cf365969668d4240e80352738b86385e2a489e5f8e5d89a6e11
@@ -1,9 +1,15 @@
1
1
  #include "nokolexbor.h"
2
+ #include "config.h"
2
3
 
3
4
  extern VALUE mNokolexbor;
4
5
  extern VALUE cNokolexborNode;
5
6
  VALUE cNokolexborDocument;
6
7
 
8
+ #ifdef HAVE_PTHREAD_H
9
+ #include <pthread.h>
10
+ pthread_key_t p_key_parser;
11
+ #endif
12
+
7
13
  static void
8
14
  free_nl_document(lxb_html_document_t *document)
9
15
  {
@@ -44,18 +50,27 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
44
50
  const char *html_c = StringValuePtr(rb_html);
45
51
  size_t html_len = RSTRING_LEN(rb_html);
46
52
 
47
- lxb_html_document_t *document;
48
-
49
- document = lxb_html_document_create();
50
- if (document == NULL) {
51
- rb_raise(rb_eRuntimeError, "Error creating document");
53
+ #ifdef HAVE_PTHREAD_H
54
+ lxb_html_parser_t *g_parser = (lxb_html_parser_t *)pthread_getspecific(p_key_parser);
55
+ #else
56
+ lxb_html_parser_t *g_parser = NULL;
57
+ #endif
58
+ if (g_parser == NULL) {
59
+ g_parser = lxb_html_parser_create();
60
+ lxb_status_t status = lxb_html_parser_init(g_parser);
61
+ if (status != LXB_STATUS_OK) {
62
+ nl_raise_lexbor_error(status);
63
+ }
64
+ g_parser->tree->scripting = true;
65
+ #ifdef HAVE_PTHREAD_H
66
+ pthread_setspecific(p_key_parser, g_parser);
67
+ #endif
52
68
  }
53
69
 
54
- lxb_dom_document_scripting_set(lxb_dom_interface_document(document), true);
70
+ lxb_html_document_t *document = lxb_html_parse(g_parser, (const lxb_char_t *)html_c, html_len);
55
71
 
56
- lxb_status_t status = lxb_html_document_parse(document, (const lxb_char_t *)html_c, html_len);
57
- if (status != LXB_STATUS_OK) {
58
- nl_raise_lexbor_error(status);
72
+ if (document == NULL) {
73
+ rb_raise(rb_eRuntimeError, "Error parsing document");
59
74
  }
60
75
 
61
76
  return TypedData_Wrap_Struct(cNokolexborDocument, &nl_document_type, document);
@@ -127,8 +142,21 @@ nl_document_root(VALUE self)
127
142
  return nl_rb_node_create(lxb_dom_document_root(doc), self);
128
143
  }
129
144
 
145
+ static void
146
+ free_parser(void *data)
147
+ {
148
+ lxb_html_parser_t *g_parser = (lxb_html_parser_t *)data;
149
+ if (g_parser != NULL) {
150
+ g_parser = lxb_html_parser_destroy(g_parser);
151
+ }
152
+ }
153
+
130
154
  void Init_nl_document(void)
131
155
  {
156
+ #ifdef HAVE_PTHREAD_H
157
+ pthread_key_create(&p_key_parser, free_parser);
158
+ #endif
159
+
132
160
  cNokolexborDocument = rb_define_class_under(mNokolexbor, "Document", cNokolexborNode);
133
161
  rb_define_singleton_method(cNokolexborDocument, "new", nl_document_new, 0);
134
162
  rb_define_singleton_method(cNokolexborDocument, "parse", nl_document_parse, 1);
@@ -873,7 +873,7 @@ static VALUE
873
873
  nl_node_equals(VALUE self, VALUE other)
874
874
  {
875
875
  if (!rb_obj_is_kind_of(other, cNokolexborNode)) {
876
- return false;
876
+ return Qfalse;
877
877
  }
878
878
  lxb_dom_node_t *node1 = nl_rb_node_unwrap(self);
879
879
  lxb_dom_node_t *node2 = nl_rb_node_unwrap(other);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nokolexbor
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokolexbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yicheng Zhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-27 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler