Changeset 156

Show
Ignore:
Timestamp:
11/12/2007 10:16:46 (12 months ago)
Author:
why
Message:

* Rakefile: build fast_xs, along with hpricot_scan.
* lib/hpricot: use String.fast_xs in place of Hpricot.xs.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/Rakefile

    r152 r156  
    1313BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}" 
    1414ARCHLIB = "lib/#{::Config::CONFIG['arch']}" 
    15 CLEAN.include ["ext/hpricot_scan/#{BIN}", "lib/**/#{BIN}", 'ext/hpricot_scan/Makefile',  
     15CLEAN.include ["ext/hpricot_scan/#{BIN}", "ext/fast_xs/#{BIN}", "lib/**/#{BIN}",  
     16               'ext/fast_xs/Makefile', 'ext/hpricot_scan/Makefile',  
    1617               '**/.*.sw?', '*.gem', '.config'] 
    1718RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source'] 
     
    6768end 
    6869 
    69 extension = "hpricot_scan" 
    70 ext = "ext/hpricot_scan" 
    71 ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" 
    72 ext_files = FileList[ 
    73   "#{ext}/*.c", 
    74   "#{ext}/*.h", 
    75   "#{ext}/*.rl", 
    76   "#{ext}/extconf.rb", 
    77   "#{ext}/Makefile", 
    78   "lib" 
    79 ]  
     70['hpricot_scan', 'fast_xs'].each do |extension| 
     71  ext = "ext/#{extension}" 
     72  ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" 
     73  ext_files = FileList[ 
     74    "#{ext}/*.c", 
     75    "#{ext}/*.h", 
     76    "#{ext}/*.rl", 
     77    "#{ext}/extconf.rb", 
     78    "#{ext}/Makefile", 
     79    "lib" 
     80  ]  
     81 
     82  desc "Builds just the #{extension} extension" 
     83  task extension.to_sym => ["#{ext}/Makefile", ext_so ] 
     84 
     85  file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do 
     86    Dir.chdir(ext) do ruby "extconf.rb" end 
     87  end 
     88 
     89  file ext_so => ext_files do 
     90    Dir.chdir(ext) do 
     91      sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') 
     92    end 
     93    mkdir_p ARCHLIB 
     94    cp ext_so, ARCHLIB 
     95  end 
     96end 
    8097 
    8198task "lib" do 
     
    84101 
    85102desc "Compiles the Ruby extension" 
    86 task :compile => [:hpricot_scan] do 
     103task :compile => [:hpricot_scan, :fast_xs] do 
    87104  if Dir.glob(File.join(ARCHLIB,"hpricot_scan.*")).length == 0 
    88105    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
     
    95112task :hpricot_scan => [:ragel] 
    96113 
    97 desc "Builds just the #{extension} extension" 
    98 task extension.to_sym => ["#{ext}/Makefile", ext_so ] 
    99  
    100 file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do 
    101   Dir.chdir(ext) do ruby "extconf.rb" end 
    102 end 
    103  
    104 file ext_so => ext_files do 
    105   Dir.chdir(ext) do 
    106     sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') 
    107   end 
    108   mkdir_p ARCHLIB 
    109   cp ext_so, ARCHLIB 
    110 end 
    111  
    112114desc "returns the ragel version" 
    113115task :ragel_version do 
     
    129131Win32Spec = SPEC.dup 
    130132Win32Spec.platform = Gem::Platform::WIN32 
    131 Win32Spec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.so"] 
     133Win32Spec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.so", "#{ARCHLIB}/fast_xs.so"] 
    132134Win32Spec.extensions = [] 
    133135   
  • trunk/lib/hpricot/builder.rb

    r145 r156  
    11require 'hpricot/tags' 
    2 require 'hpricot/xchar' 
     2require 'fast_xs' 
    33require 'hpricot/blankslate' 
    44 
    55module Hpricot 
     6  PREDEFINED = { 
     7    34 => '"', # quotation mark 
     8    38 => '&',  # ampersand 
     9    60 => '<',   # left angle bracket 
     10    62 => '>'    # right angle bracket 
     11  } 
     12  PREDEFINED_U = PREDEFINED.inject({}) { |hsh, (k, v)| hsh[v] = k; hsh } 
     13 
     14  # XML unescape 
     15  def self.uxs(str) 
     16    str.to_s. 
     17        gsub(/\&\w+;/) { |x| (PREDEFINED_U[x] || ??).chr }. 
     18        gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") } 
     19  end 
     20 
    621  def self.build(ele = Doc.new, assigns = {}, &blk) 
    722    ele.extend Builder 
     
    3348    # Write a +string+ to the HTML stream, making sure to escape it. 
    3449    def text!(string) 
    35       @children << Text.new(Hpricot.xs(string)) 
     50      @children << Text.new(string.fast_xs) 
    3651    end 
    3752 
     
    8095          Hpricot.make(x.to_html) 
    8196        elsif x 
    82           Text.new(Hpricot.xs(x)) 
     97          Text.new(x.fast_xs) 
    8398        end 
    8499      end.flatten) 
    85100      attrs = attrs.inject({}) do |hsh, ath| 
    86101        ath.each do |k, v| 
    87           hsh[k] = Hpricot.xs(v.to_s) if v 
     102          hsh[k] = v.to_s.fast_xs if v 
    88103        end 
    89104        hsh 
  • trunk/lib/hpricot/traverse.rb

    r155 r156  
    817817      altered! 
    818818      self.raw_attributes ||= {} 
    819       self.raw_attributes[name.to_s] = Hpricot.xs(val) 
     819      self.raw_attributes[name.to_s] = val.fast_xs 
    820820    end 
    821821    alias_method :[]=, :set_attribute