Removed Mutex usage from XML::Text

Instead of trying to make this class thread-safe I'm going with the
option of simply declaring it unsafe to mutate instances of XML::Text
while reading it in parallel. This removes the need for Mutex
allocations and keeps the code simple.

Fixes #82
This commit is contained in:
Yorick Peterse 2015-03-21 01:27:00 +01:00
parent c647f064b5
commit 31e93e54f9
1 changed files with 6 additions and 12 deletions

View File

@ -8,7 +8,6 @@ module Oga
def initialize(*args) def initialize(*args)
super super
@mutex = Mutex.new
@decoded = false @decoded = false
end end
@ -16,12 +15,9 @@ module Oga
# @param [String] value # @param [String] value
# #
def text=(value) def text=(value)
# In case of concurrent text/text= calls.
@mutex.synchronize do
@decoded = false @decoded = false
@text = value @text = value
end end
end
## ##
# Returns the text as a String. Upon the first call any XML/HTML entities # Returns the text as a String. Upon the first call any XML/HTML entities
@ -30,13 +26,11 @@ module Oga
# @return [String] # @return [String]
# #
def text def text
@mutex.synchronize do
unless @decoded unless @decoded
decoder = html? ? HTML::Entities : Entities decoder = html? ? HTML::Entities : Entities
@text = decoder.decode(@text) @text = decoder.decode(@text)
@decoded = true @decoded = true
end end
end
return @text return @text
end end